2 * linux/arch/arm/mach-footbridge/isa-timer.c
4 * Copyright (C) 1998 Russell King.
5 * Copyright (C) 1998 Phil Blundell
7 #include <linux/clockchips.h>
8 #include <linux/clocksource.h>
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
13 #include <linux/timex.h>
17 #include <asm/mach/time.h>
24 #define PIT_LATCH ((PIT_TICK_RATE + HZ / 2) / HZ)
26 static cycle_t pit_read(struct clocksource *cs)
34 raw_local_irq_save(flags);
37 outb_p(0x00, PIT_MODE); /* latch the count */
38 count = inb_p(PIT_CH0); /* read the latched count */
39 count |= inb_p(PIT_CH0) << 8;
41 if (count > old_count && jifs == old_jifs)
47 raw_local_irq_restore(flags);
49 count = (PIT_LATCH - 1) - count;
51 return (cycle_t)(jifs * PIT_LATCH) + count;
54 static struct clocksource pit_cs = {
58 .mask = CLOCKSOURCE_MASK(32),
61 static void pit_set_mode(enum clock_event_mode mode,
62 struct clock_event_device *evt)
66 raw_local_irq_save(flags);
69 case CLOCK_EVT_MODE_PERIODIC:
70 outb_p(0x34, PIT_MODE);
71 outb_p(PIT_LATCH & 0xff, PIT_CH0);
72 outb_p(PIT_LATCH >> 8, PIT_CH0);
75 case CLOCK_EVT_MODE_SHUTDOWN:
76 case CLOCK_EVT_MODE_UNUSED:
77 outb_p(0x30, PIT_MODE);
82 case CLOCK_EVT_MODE_ONESHOT:
83 case CLOCK_EVT_MODE_RESUME:
86 local_irq_restore(flags);
89 static int pit_set_next_event(unsigned long delta,
90 struct clock_event_device *evt)
95 static struct clock_event_device pit_ce = {
97 .features = CLOCK_EVT_FEAT_PERIODIC,
98 .set_mode = pit_set_mode,
99 .set_next_event = pit_set_next_event,
103 static irqreturn_t pit_timer_interrupt(int irq, void *dev_id)
105 struct clock_event_device *ce = dev_id;
106 ce->event_handler(ce);
110 static struct irqaction pit_timer_irq = {
112 .handler = pit_timer_interrupt,
113 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
117 static void __init isa_timer_init(void)
119 pit_ce.cpumask = cpumask_of(smp_processor_id());
120 pit_ce.mult = div_sc(PIT_TICK_RATE, NSEC_PER_SEC, pit_ce.shift);
121 pit_ce.max_delta_ns = clockevent_delta2ns(0x7fff, &pit_ce);
122 pit_ce.min_delta_ns = clockevent_delta2ns(0x000f, &pit_ce);
124 clocksource_register_hz(&pit_cs, PIT_TICK_RATE);
126 setup_irq(pit_ce.irq, &pit_timer_irq);
127 clockevents_register_device(&pit_ce);
130 struct sys_timer isa_timer = {
131 .init = isa_timer_init,