diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-01-17 11:20:56 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-05-02 04:35:36 -0400 |
commit | 6be4826e37122b25cb10b215fc84c3a0b1fe1402 (patch) | |
tree | 4aad2c701f4b516e3bb75d23c11e0f4380d760cb /arch/arm/mach-integrator/integrator_ap.c | |
parent | 5a46334ac688fb538b335599e1ff3b6cfaf769e9 (diff) |
ARM: Integrator: move 16-bit timer support to Integrator/AP
Only Integrator/AP has 16-bit timers, so move the support into the
Integrator/AP specific support files.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mach-integrator/integrator_ap.c')
-rw-r--r-- | arch/arm/mach-integrator/integrator_ap.c | 158 |
1 files changed, 155 insertions, 3 deletions
diff --git a/arch/arm/mach-integrator/integrator_ap.c b/arch/arm/mach-integrator/integrator_ap.c index c89b231898e6..227cf4d05088 100644 --- a/arch/arm/mach-integrator/integrator_ap.c +++ b/arch/arm/mach-integrator/integrator_ap.c | |||
@@ -27,10 +27,14 @@ | |||
27 | #include <linux/sysdev.h> | 27 | #include <linux/sysdev.h> |
28 | #include <linux/amba/bus.h> | 28 | #include <linux/amba/bus.h> |
29 | #include <linux/amba/kmi.h> | 29 | #include <linux/amba/kmi.h> |
30 | #include <linux/clocksource.h> | ||
31 | #include <linux/clockchips.h> | ||
32 | #include <linux/interrupt.h> | ||
30 | #include <linux/io.h> | 33 | #include <linux/io.h> |
31 | 34 | ||
32 | #include <mach/hardware.h> | 35 | #include <mach/hardware.h> |
33 | #include <mach/platform.h> | 36 | #include <mach/platform.h> |
37 | #include <asm/hardware/arm_timer.h> | ||
34 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
35 | #include <asm/setup.h> | 39 | #include <asm/setup.h> |
36 | #include <asm/param.h> /* HZ */ | 40 | #include <asm/param.h> /* HZ */ |
@@ -44,8 +48,6 @@ | |||
44 | #include <asm/mach/map.h> | 48 | #include <asm/mach/map.h> |
45 | #include <asm/mach/time.h> | 49 | #include <asm/mach/time.h> |
46 | 50 | ||
47 | #include "common.h" | ||
48 | |||
49 | /* | 51 | /* |
50 | * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx | 52 | * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx |
51 | * is the (PA >> 12). | 53 | * is the (PA >> 12). |
@@ -335,9 +337,159 @@ static void __init ap_init(void) | |||
335 | } | 337 | } |
336 | } | 338 | } |
337 | 339 | ||
340 | /* | ||
341 | * Where is the timer (VA)? | ||
342 | */ | ||
343 | #define TIMER0_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER0_BASE) | ||
344 | #define TIMER1_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER1_BASE) | ||
345 | #define TIMER2_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER2_BASE) | ||
346 | |||
347 | /* | ||
348 | * How long is the timer interval? | ||
349 | */ | ||
350 | #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10) | ||
351 | #if TIMER_INTERVAL >= 0x100000 | ||
352 | #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC) | ||
353 | #elif TIMER_INTERVAL >= 0x10000 | ||
354 | #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC) | ||
355 | #else | ||
356 | #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC) | ||
357 | #endif | ||
358 | |||
359 | static unsigned long timer_reload; | ||
360 | |||
361 | static void __iomem * const clksrc_base = (void __iomem *)TIMER2_VA_BASE; | ||
362 | |||
363 | static cycle_t timersp_read(struct clocksource *cs) | ||
364 | { | ||
365 | return ~(readl(clksrc_base + TIMER_VALUE) & 0xffff); | ||
366 | } | ||
367 | |||
368 | static struct clocksource clocksource_timersp = { | ||
369 | .name = "timer2", | ||
370 | .rating = 200, | ||
371 | .read = timersp_read, | ||
372 | .mask = CLOCKSOURCE_MASK(16), | ||
373 | .shift = 16, | ||
374 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | ||
375 | }; | ||
376 | |||
377 | static void integrator_clocksource_init(u32 khz) | ||
378 | { | ||
379 | struct clocksource *cs = &clocksource_timersp; | ||
380 | void __iomem *base = clksrc_base; | ||
381 | u32 ctrl = TIMER_CTRL_ENABLE; | ||
382 | |||
383 | if (khz >= 1500) { | ||
384 | khz /= 16; | ||
385 | ctrl = TIMER_CTRL_DIV16; | ||
386 | } | ||
387 | |||
388 | writel(ctrl, base + TIMER_CTRL); | ||
389 | writel(0xffff, base + TIMER_LOAD); | ||
390 | |||
391 | cs->mult = clocksource_khz2mult(khz, cs->shift); | ||
392 | clocksource_register(cs); | ||
393 | } | ||
394 | |||
395 | static void __iomem * const clkevt_base = (void __iomem *)TIMER1_VA_BASE; | ||
396 | |||
397 | /* | ||
398 | * IRQ handler for the timer | ||
399 | */ | ||
400 | static irqreturn_t integrator_timer_interrupt(int irq, void *dev_id) | ||
401 | { | ||
402 | struct clock_event_device *evt = dev_id; | ||
403 | |||
404 | /* clear the interrupt */ | ||
405 | writel(1, clkevt_base + TIMER_INTCLR); | ||
406 | |||
407 | evt->event_handler(evt); | ||
408 | |||
409 | return IRQ_HANDLED; | ||
410 | } | ||
411 | |||
412 | static void clkevt_set_mode(enum clock_event_mode mode, struct clock_event_device *evt) | ||
413 | { | ||
414 | u32 ctrl = readl(clkevt_base + TIMER_CTRL) & ~TIMER_CTRL_ENABLE; | ||
415 | |||
416 | BUG_ON(mode == CLOCK_EVT_MODE_ONESHOT); | ||
417 | |||
418 | if (mode == CLOCK_EVT_MODE_PERIODIC) { | ||
419 | writel(ctrl, clkevt_base + TIMER_CTRL); | ||
420 | writel(timer_reload, clkevt_base + TIMER_LOAD); | ||
421 | ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE; | ||
422 | } | ||
423 | |||
424 | writel(ctrl, clkevt_base + TIMER_CTRL); | ||
425 | } | ||
426 | |||
427 | static int clkevt_set_next_event(unsigned long next, struct clock_event_device *evt) | ||
428 | { | ||
429 | unsigned long ctrl = readl(clkevt_base + TIMER_CTRL); | ||
430 | |||
431 | writel(ctrl & ~TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL); | ||
432 | writel(next, clkevt_base + TIMER_LOAD); | ||
433 | writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL); | ||
434 | |||
435 | return 0; | ||
436 | } | ||
437 | |||
438 | static struct clock_event_device integrator_clockevent = { | ||
439 | .name = "timer1", | ||
440 | .shift = 34, | ||
441 | .features = CLOCK_EVT_FEAT_PERIODIC, | ||
442 | .set_mode = clkevt_set_mode, | ||
443 | .set_next_event = clkevt_set_next_event, | ||
444 | .rating = 300, | ||
445 | .cpumask = cpu_all_mask, | ||
446 | }; | ||
447 | |||
448 | static struct irqaction integrator_timer_irq = { | ||
449 | .name = "timer", | ||
450 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, | ||
451 | .handler = integrator_timer_interrupt, | ||
452 | .dev_id = &integrator_clockevent, | ||
453 | }; | ||
454 | |||
455 | static void integrator_clockevent_init(u32 khz) | ||
456 | { | ||
457 | struct clock_event_device *evt = &integrator_clockevent; | ||
458 | unsigned int ctrl = 0; | ||
459 | |||
460 | if (khz * 1000 > 0x100000 * HZ) { | ||
461 | khz /= 256; | ||
462 | ctrl |= TIMER_CTRL_DIV256; | ||
463 | } else if (khz * 1000 > 0x10000 * HZ) { | ||
464 | khz /= 16; | ||
465 | ctrl |= TIMER_CTRL_DIV16; | ||
466 | } | ||
467 | |||
468 | timer_reload = khz * 1000 / HZ; | ||
469 | writel(ctrl, clkevt_base + TIMER_CTRL); | ||
470 | |||
471 | evt->irq = IRQ_TIMERINT1; | ||
472 | evt->mult = div_sc(khz, NSEC_PER_MSEC, evt->shift); | ||
473 | evt->max_delta_ns = clockevent_delta2ns(0xffff, evt); | ||
474 | evt->min_delta_ns = clockevent_delta2ns(0xf, evt); | ||
475 | |||
476 | setup_irq(IRQ_TIMERINT1, &integrator_timer_irq); | ||
477 | clockevents_register_device(evt); | ||
478 | } | ||
479 | |||
480 | /* | ||
481 | * Set up timer(s). | ||
482 | */ | ||
338 | static void __init ap_init_timer(void) | 483 | static void __init ap_init_timer(void) |
339 | { | 484 | { |
340 | integrator_time_init(TICKS_PER_uSEC * 1000, 0); | 485 | u32 khz = TICKS_PER_uSEC * 1000; |
486 | |||
487 | writel(0, TIMER0_VA_BASE + TIMER_CTRL); | ||
488 | writel(0, TIMER1_VA_BASE + TIMER_CTRL); | ||
489 | writel(0, TIMER2_VA_BASE + TIMER_CTRL); | ||
490 | |||
491 | integrator_clocksource_init(khz); | ||
492 | integrator_clockevent_init(khz); | ||
341 | } | 493 | } |
342 | 494 | ||
343 | static struct sys_timer ap_timer = { | 495 | static struct sys_timer ap_timer = { |