Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-footbridge/isa-timer.c |
| 3 | * |
| 4 | * Copyright (C) 1998 Russell King. |
| 5 | * Copyright (C) 1998 Phil Blundell |
| 6 | */ |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 7 | #include <linux/clockchips.h> |
| 8 | #include <linux/clocksource.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/init.h> |
| 10 | #include <linux/interrupt.h> |
Thomas Gleixner | 55e8698 | 2006-07-01 22:32:17 +0100 | [diff] [blame] | 11 | #include <linux/irq.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 12 | #include <linux/io.h> |
Russell King | 8c414ff | 2011-05-08 18:50:20 +0100 | [diff] [blame] | 13 | #include <linux/spinlock.h> |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 14 | #include <linux/timex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/irq.h> |
Russell King | 8c414ff | 2011-05-08 18:50:20 +0100 | [diff] [blame] | 17 | #include <asm/i8253.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/mach/time.h> |
| 19 | |
| 20 | #include "common.h" |
| 21 | |
Russell King | 8c414ff | 2011-05-08 18:50:20 +0100 | [diff] [blame] | 22 | DEFINE_RAW_SPINLOCK(i8253_lock); |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 23 | |
| 24 | static void pit_set_mode(enum clock_event_mode mode, |
| 25 | struct clock_event_device *evt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 27 | unsigned long flags; |
| 28 | |
| 29 | raw_local_irq_save(flags); |
| 30 | |
| 31 | switch (mode) { |
| 32 | case CLOCK_EVT_MODE_PERIODIC: |
| 33 | outb_p(0x34, PIT_MODE); |
| 34 | outb_p(PIT_LATCH & 0xff, PIT_CH0); |
| 35 | outb_p(PIT_LATCH >> 8, PIT_CH0); |
| 36 | break; |
| 37 | |
| 38 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 39 | case CLOCK_EVT_MODE_UNUSED: |
| 40 | outb_p(0x30, PIT_MODE); |
| 41 | outb_p(0, PIT_CH0); |
| 42 | outb_p(0, PIT_CH0); |
| 43 | break; |
| 44 | |
| 45 | case CLOCK_EVT_MODE_ONESHOT: |
| 46 | case CLOCK_EVT_MODE_RESUME: |
| 47 | break; |
| 48 | } |
| 49 | local_irq_restore(flags); |
| 50 | } |
| 51 | |
| 52 | static int pit_set_next_event(unsigned long delta, |
| 53 | struct clock_event_device *evt) |
| 54 | { |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static struct clock_event_device pit_ce = { |
| 59 | .name = "pit", |
| 60 | .features = CLOCK_EVT_FEAT_PERIODIC, |
| 61 | .set_mode = pit_set_mode, |
| 62 | .set_next_event = pit_set_next_event, |
| 63 | .shift = 32, |
| 64 | }; |
| 65 | |
| 66 | static irqreturn_t pit_timer_interrupt(int irq, void *dev_id) |
| 67 | { |
| 68 | struct clock_event_device *ce = dev_id; |
| 69 | ce->event_handler(ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return IRQ_HANDLED; |
| 71 | } |
| 72 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 73 | static struct irqaction pit_timer_irq = { |
| 74 | .name = "pit", |
| 75 | .handler = pit_timer_interrupt, |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 76 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 77 | .dev_id = &pit_ce, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | static void __init isa_timer_init(void) |
| 81 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 82 | pit_ce.cpumask = cpumask_of(smp_processor_id()); |
| 83 | pit_ce.mult = div_sc(PIT_TICK_RATE, NSEC_PER_SEC, pit_ce.shift); |
| 84 | pit_ce.max_delta_ns = clockevent_delta2ns(0x7fff, &pit_ce); |
| 85 | pit_ce.min_delta_ns = clockevent_delta2ns(0x000f, &pit_ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Russell King | 8c414ff | 2011-05-08 18:50:20 +0100 | [diff] [blame] | 87 | clocksource_i8253_init(); |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 88 | |
| 89 | setup_irq(pit_ce.irq, &pit_timer_irq); |
| 90 | clockevents_register_device(&pit_ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | struct sys_timer isa_timer = { |
| 94 | .init = isa_timer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; |