diff options
author | Stefan Agner <stefan@agner.ch> | 2009-05-12 13:30:41 -0400 |
---|---|---|
committer | Nicolas Pitre <nico@cam.org> | 2009-06-08 13:04:54 -0400 |
commit | 8a3269fc21cc4405d80b362139c078cf655a505a (patch) | |
tree | 5b8167964d803515471e1a7450eb1f4fd74655c9 /arch/arm/plat-orion | |
parent | e50b6befae9ea91c2d190fb78ff1e06a0b950add (diff) |
[ARM] orion: sched_clock implementation for orion platforms
sched_clock implementation for orion platform. Its realized using
free-running clocksource timer, which provides a resolution of 7.5ns
(depending on tclk). It's derived from PXA's sched_clock implementation.
[ nico: renamed orion2ns to tclk2ns, fixed max value in the comment ]
Signed-off-by: Stefan Agner <stefan.agner@yahoo.com>
Signed-off-by: Nicolas Pitre <nico@marvell.com>
Diffstat (limited to 'arch/arm/plat-orion')
-rw-r--r-- | arch/arm/plat-orion/time.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/arch/arm/plat-orion/time.c b/arch/arm/plat-orion/time.c index de8a001fc3a9..b856cec81702 100644 --- a/arch/arm/plat-orion/time.c +++ b/arch/arm/plat-orion/time.c | |||
@@ -17,6 +17,9 @@ | |||
17 | #include <linux/irq.h> | 17 | #include <linux/irq.h> |
18 | #include <asm/mach/time.h> | 18 | #include <asm/mach/time.h> |
19 | #include <mach/bridge-regs.h> | 19 | #include <mach/bridge-regs.h> |
20 | #include <mach/hardware.h> | ||
21 | #include <linux/sched.h> | ||
22 | #include <linux/cnt32_to_63.h> | ||
20 | 23 | ||
21 | /* | 24 | /* |
22 | * Number of timer ticks per jiffy. | 25 | * Number of timer ticks per jiffy. |
@@ -39,6 +42,36 @@ static u32 ticks_per_jiffy; | |||
39 | 42 | ||
40 | 43 | ||
41 | /* | 44 | /* |
45 | * Orion's sched_clock implementation. It has a resolution of | ||
46 | * at least 7.5ns (133MHz TCLK) and a maximum value of 834 days. | ||
47 | */ | ||
48 | #define TCLK2NS_SCALE_FACTOR 8 | ||
49 | |||
50 | static unsigned long tclk2ns_scale; | ||
51 | |||
52 | static void __init set_tclk2ns_scale(unsigned long tclk) | ||
53 | { | ||
54 | unsigned long long v = NSEC_PER_SEC; | ||
55 | v <<= TCLK2NS_SCALE_FACTOR; | ||
56 | v += tclk/2; | ||
57 | do_div(v, tclk); | ||
58 | /* | ||
59 | * We want an even value to automatically clear the top bit | ||
60 | * returned by cnt32_to_63() without an additional run time | ||
61 | * instruction. So if the LSB is 1 then round it up. | ||
62 | */ | ||
63 | if (v & 1) | ||
64 | v++; | ||
65 | tclk2ns_scale = v; | ||
66 | } | ||
67 | |||
68 | unsigned long long sched_clock(void) | ||
69 | { | ||
70 | unsigned long long v = cnt32_to_63(0xffffffff - readl(TIMER0_VAL)); | ||
71 | return (v * tclk2ns_scale) >> TCLK2NS_SCALE_FACTOR; | ||
72 | } | ||
73 | |||
74 | /* | ||
42 | * Clocksource handling. | 75 | * Clocksource handling. |
43 | */ | 76 | */ |
44 | static cycle_t orion_clksrc_read(struct clocksource *cs) | 77 | static cycle_t orion_clksrc_read(struct clocksource *cs) |
@@ -176,6 +209,10 @@ void __init orion_time_init(unsigned int irq, unsigned int tclk) | |||
176 | 209 | ||
177 | ticks_per_jiffy = (tclk + HZ/2) / HZ; | 210 | ticks_per_jiffy = (tclk + HZ/2) / HZ; |
178 | 211 | ||
212 | /* | ||
213 | * Set scale for sched_clock | ||
214 | */ | ||
215 | set_tclk2ns_scale(tclk); | ||
179 | 216 | ||
180 | /* | 217 | /* |
181 | * Setup free-running clocksource timer (interrupts | 218 | * Setup free-running clocksource timer (interrupts |