diff options
author | Yi Li <yi.li@analog.com> | 2009-09-15 04:55:47 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-12-15 00:13:43 -0500 |
commit | 298571249a1990cd3c6c6ab40250a4a9c18ab5d1 (patch) | |
tree | 5fb7f04e8b68b80e4b3925116664a280cf22cd8c /arch/blackfin/kernel/time-ts.c | |
parent | ceb33be95afcfbc4079af334835a345288f9f6ca (diff) |
Blackfin: use common code for cycle->nanosecond conversion
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>
Diffstat (limited to 'arch/blackfin/kernel/time-ts.c')
-rw-r--r-- | arch/blackfin/kernel/time-ts.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/arch/blackfin/kernel/time-ts.c b/arch/blackfin/kernel/time-ts.c index 2855f0ff865c..eef528389d2f 100644 --- a/arch/blackfin/kernel/time-ts.c +++ b/arch/blackfin/kernel/time-ts.c | |||
@@ -46,20 +46,8 @@ | |||
46 | 46 | ||
47 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | 47 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ |
48 | 48 | ||
49 | static inline unsigned long cyc2ns_scale(unsigned long cpu_khz) | ||
50 | { | ||
51 | return (1000000 << CYC2NS_SCALE_FACTOR) / cpu_khz; | ||
52 | } | ||
53 | |||
54 | static inline unsigned long long cycles_2_ns(cycle_t cyc, unsigned long cyc2ns_scale) | ||
55 | { | ||
56 | return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR; | ||
57 | } | ||
58 | |||
59 | #if defined(CONFIG_CYCLES_CLOCKSOURCE) | 49 | #if defined(CONFIG_CYCLES_CLOCKSOURCE) |
60 | 50 | ||
61 | static unsigned long cycles_cyc2ns_scale; | ||
62 | |||
63 | static notrace cycle_t bfin_read_cycles(struct clocksource *cs) | 51 | static notrace cycle_t bfin_read_cycles(struct clocksource *cs) |
64 | { | 52 | { |
65 | return __bfin_cycles_off + (get_cycles() << __bfin_cycles_mod); | 53 | return __bfin_cycles_off + (get_cycles() << __bfin_cycles_mod); |
@@ -70,19 +58,17 @@ static struct clocksource bfin_cs_cycles = { | |||
70 | .rating = 400, | 58 | .rating = 400, |
71 | .read = bfin_read_cycles, | 59 | .read = bfin_read_cycles, |
72 | .mask = CLOCKSOURCE_MASK(64), | 60 | .mask = CLOCKSOURCE_MASK(64), |
73 | .shift = 22, | 61 | .shift = CYC2NS_SCALE_FACTOR, |
74 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 62 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
75 | }; | 63 | }; |
76 | 64 | ||
77 | static inline unsigned long long bfin_cs_cycles_sched_clock(void) | 65 | static inline unsigned long long bfin_cs_cycles_sched_clock(void) |
78 | { | 66 | { |
79 | return cycles_2_ns(bfin_read_cycles(&bfin_cs_cycles), cycles_cyc2ns_scale); | 67 | return cyc2ns(&bfin_cs_cycles, bfin_read_cycles(&bfin_cs_cycles)); |
80 | } | 68 | } |
81 | 69 | ||
82 | static int __init bfin_cs_cycles_init(void) | 70 | static int __init bfin_cs_cycles_init(void) |
83 | { | 71 | { |
84 | cycles_cyc2ns_scale = cyc2ns_scale(get_cclk() / 1000); | ||
85 | |||
86 | bfin_cs_cycles.mult = \ | 72 | bfin_cs_cycles.mult = \ |
87 | clocksource_hz2mult(get_cclk(), bfin_cs_cycles.shift); | 73 | clocksource_hz2mult(get_cclk(), bfin_cs_cycles.shift); |
88 | 74 | ||
@@ -97,8 +83,6 @@ static int __init bfin_cs_cycles_init(void) | |||
97 | 83 | ||
98 | #ifdef CONFIG_GPTMR0_CLOCKSOURCE | 84 | #ifdef CONFIG_GPTMR0_CLOCKSOURCE |
99 | 85 | ||
100 | unsigned long gptimer0_cyc2ns_scale; | ||
101 | |||
102 | void __init setup_gptimer0(void) | 86 | void __init setup_gptimer0(void) |
103 | { | 87 | { |
104 | disable_gptimers(TIMER0bit); | 88 | disable_gptimers(TIMER0bit); |
@@ -121,19 +105,17 @@ static struct clocksource bfin_cs_gptimer0 = { | |||
121 | .rating = 350, | 105 | .rating = 350, |
122 | .read = bfin_read_gptimer0, | 106 | .read = bfin_read_gptimer0, |
123 | .mask = CLOCKSOURCE_MASK(32), | 107 | .mask = CLOCKSOURCE_MASK(32), |
124 | .shift = 22, | 108 | .shift = CYC2NS_SCALE_FACTOR, |
125 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 109 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
126 | }; | 110 | }; |
127 | 111 | ||
128 | static inline unsigned long long bfin_cs_gptimer0_sched_clock(void) | 112 | static inline unsigned long long bfin_cs_gptimer0_sched_clock(void) |
129 | { | 113 | { |
130 | return cycles_2_ns(bfin_read_TIMER0_COUNTER(), gptimer0_cyc2ns_scale); | 114 | return cyc2ns(&bfin_cs_gptimer0, bfin_read_TIMER0_COUNTER()); |
131 | } | 115 | } |
132 | 116 | ||
133 | static int __init bfin_cs_gptimer0_init(void) | 117 | static int __init bfin_cs_gptimer0_init(void) |
134 | { | 118 | { |
135 | gptimer0_cyc2ns_scale = cyc2ns_scale(get_sclk() / 1000); | ||
136 | |||
137 | setup_gptimer0(); | 119 | setup_gptimer0(); |
138 | 120 | ||
139 | bfin_cs_gptimer0.mult = \ | 121 | bfin_cs_gptimer0.mult = \ |