diff options
Diffstat (limited to 'arch/arm/mach-omap1/time.c')
-rw-r--r-- | arch/arm/mach-omap1/time.c | 100 |
1 files changed, 93 insertions, 7 deletions
diff --git a/arch/arm/mach-omap1/time.c b/arch/arm/mach-omap1/time.c index ed7a61ff916..6885d2fac18 100644 --- a/arch/arm/mach-omap1/time.c +++ b/arch/arm/mach-omap1/time.c | |||
@@ -49,11 +49,15 @@ | |||
49 | #include <mach/hardware.h> | 49 | #include <mach/hardware.h> |
50 | #include <asm/leds.h> | 50 | #include <asm/leds.h> |
51 | #include <asm/irq.h> | 51 | #include <asm/irq.h> |
52 | #include <asm/sched_clock.h> | ||
53 | |||
52 | #include <asm/mach/irq.h> | 54 | #include <asm/mach/irq.h> |
53 | #include <asm/mach/time.h> | 55 | #include <asm/mach/time.h> |
54 | 56 | ||
55 | #include <plat/common.h> | 57 | #include <plat/common.h> |
56 | 58 | ||
59 | #ifdef CONFIG_OMAP_MPU_TIMER | ||
60 | |||
57 | #define OMAP_MPU_TIMER_BASE OMAP_MPU_TIMER1_BASE | 61 | #define OMAP_MPU_TIMER_BASE OMAP_MPU_TIMER1_BASE |
58 | #define OMAP_MPU_TIMER_OFFSET 0x100 | 62 | #define OMAP_MPU_TIMER_OFFSET 0x100 |
59 | 63 | ||
@@ -67,7 +71,7 @@ typedef struct { | |||
67 | ((volatile omap_mpu_timer_regs_t*)OMAP1_IO_ADDRESS(OMAP_MPU_TIMER_BASE + \ | 71 | ((volatile omap_mpu_timer_regs_t*)OMAP1_IO_ADDRESS(OMAP_MPU_TIMER_BASE + \ |
68 | (n)*OMAP_MPU_TIMER_OFFSET)) | 72 | (n)*OMAP_MPU_TIMER_OFFSET)) |
69 | 73 | ||
70 | static inline unsigned long omap_mpu_timer_read(int nr) | 74 | static inline unsigned long notrace omap_mpu_timer_read(int nr) |
71 | { | 75 | { |
72 | volatile omap_mpu_timer_regs_t* timer = omap_mpu_timer_base(nr); | 76 | volatile omap_mpu_timer_regs_t* timer = omap_mpu_timer_base(nr); |
73 | return timer->read_tim; | 77 | return timer->read_tim; |
@@ -212,6 +216,32 @@ static struct clocksource clocksource_mpu = { | |||
212 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 216 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
213 | }; | 217 | }; |
214 | 218 | ||
219 | static DEFINE_CLOCK_DATA(cd); | ||
220 | |||
221 | static inline unsigned long long notrace _omap_mpu_sched_clock(void) | ||
222 | { | ||
223 | u32 cyc = mpu_read(&clocksource_mpu); | ||
224 | return cyc_to_sched_clock(&cd, cyc, (u32)~0); | ||
225 | } | ||
226 | |||
227 | #ifndef CONFIG_OMAP_32K_TIMER | ||
228 | unsigned long long notrace sched_clock(void) | ||
229 | { | ||
230 | return _omap_mpu_sched_clock(); | ||
231 | } | ||
232 | #else | ||
233 | static unsigned long long notrace omap_mpu_sched_clock(void) | ||
234 | { | ||
235 | return _omap_mpu_sched_clock(); | ||
236 | } | ||
237 | #endif | ||
238 | |||
239 | static void notrace mpu_update_sched_clock(void) | ||
240 | { | ||
241 | u32 cyc = mpu_read(&clocksource_mpu); | ||
242 | update_sched_clock(&cd, cyc, (u32)~0); | ||
243 | } | ||
244 | |||
215 | static void __init omap_init_clocksource(unsigned long rate) | 245 | static void __init omap_init_clocksource(unsigned long rate) |
216 | { | 246 | { |
217 | static char err[] __initdata = KERN_ERR | 247 | static char err[] __initdata = KERN_ERR |
@@ -219,17 +249,13 @@ static void __init omap_init_clocksource(unsigned long rate) | |||
219 | 249 | ||
220 | setup_irq(INT_TIMER2, &omap_mpu_timer2_irq); | 250 | setup_irq(INT_TIMER2, &omap_mpu_timer2_irq); |
221 | omap_mpu_timer_start(1, ~0, 1); | 251 | omap_mpu_timer_start(1, ~0, 1); |
252 | init_sched_clock(&cd, mpu_update_sched_clock, 32, rate); | ||
222 | 253 | ||
223 | if (clocksource_register_hz(&clocksource_mpu, rate)) | 254 | if (clocksource_register_hz(&clocksource_mpu, rate)) |
224 | printk(err, clocksource_mpu.name); | 255 | printk(err, clocksource_mpu.name); |
225 | } | 256 | } |
226 | 257 | ||
227 | /* | 258 | static void __init omap_mpu_timer_init(void) |
228 | * --------------------------------------------------------------------------- | ||
229 | * Timer initialization | ||
230 | * --------------------------------------------------------------------------- | ||
231 | */ | ||
232 | static void __init omap_timer_init(void) | ||
233 | { | 259 | { |
234 | struct clk *ck_ref = clk_get(NULL, "ck_ref"); | 260 | struct clk *ck_ref = clk_get(NULL, "ck_ref"); |
235 | unsigned long rate; | 261 | unsigned long rate; |
@@ -246,6 +272,66 @@ static void __init omap_timer_init(void) | |||
246 | omap_init_clocksource(rate); | 272 | omap_init_clocksource(rate); |
247 | } | 273 | } |
248 | 274 | ||
275 | #else | ||
276 | static inline void omap_mpu_timer_init(void) | ||
277 | { | ||
278 | pr_err("Bogus timer, should not happen\n"); | ||
279 | } | ||
280 | #endif /* CONFIG_OMAP_MPU_TIMER */ | ||
281 | |||
282 | #if defined(CONFIG_OMAP_MPU_TIMER) && defined(CONFIG_OMAP_32K_TIMER) | ||
283 | static unsigned long long (*preferred_sched_clock)(void); | ||
284 | |||
285 | unsigned long long notrace sched_clock(void) | ||
286 | { | ||
287 | if (!preferred_sched_clock) | ||
288 | return 0; | ||
289 | |||
290 | return preferred_sched_clock(); | ||
291 | } | ||
292 | |||
293 | static inline void preferred_sched_clock_init(bool use_32k_sched_clock) | ||
294 | { | ||
295 | if (use_32k_sched_clock) | ||
296 | preferred_sched_clock = omap_32k_sched_clock; | ||
297 | else | ||
298 | preferred_sched_clock = omap_mpu_sched_clock; | ||
299 | } | ||
300 | #else | ||
301 | static inline void preferred_sched_clock_init(bool use_32k_sched_clcok) | ||
302 | { | ||
303 | } | ||
304 | #endif | ||
305 | |||
306 | static inline int omap_32k_timer_usable(void) | ||
307 | { | ||
308 | int res = false; | ||
309 | |||
310 | if (cpu_is_omap730() || cpu_is_omap15xx()) | ||
311 | return res; | ||
312 | |||
313 | #ifdef CONFIG_OMAP_32K_TIMER | ||
314 | res = omap_32k_timer_init(); | ||
315 | #endif | ||
316 | |||
317 | return res; | ||
318 | } | ||
319 | |||
320 | /* | ||
321 | * --------------------------------------------------------------------------- | ||
322 | * Timer initialization | ||
323 | * --------------------------------------------------------------------------- | ||
324 | */ | ||
325 | static void __init omap_timer_init(void) | ||
326 | { | ||
327 | if (omap_32k_timer_usable()) { | ||
328 | preferred_sched_clock_init(1); | ||
329 | } else { | ||
330 | omap_mpu_timer_init(); | ||
331 | preferred_sched_clock_init(0); | ||
332 | } | ||
333 | } | ||
334 | |||
249 | struct sys_timer omap_timer = { | 335 | struct sys_timer omap_timer = { |
250 | .init = omap_timer_init, | 336 | .init = omap_timer_init, |
251 | }; | 337 | }; |