aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2011-06-09 09:08:27 -0400
committerThomas Gleixner <tglx@linutronix.de>2011-07-01 04:37:14 -0400
commit2d02612f61cc15b2025c90e32ed4a43eaa6753cd (patch)
tree2101a7b144b529c163e6a94bbc1c081d2077c26e /arch
parent0a779c571314b7951ff12edac80aa0cbe7c12b6e (diff)
mips: Use common i8253 clockevent
Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Russell King <linux@arm.linux.org.uk> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: John Stultz <john.stultz@linaro.org> Link: http://lkml.kernel.org/r/20110609130622.133068765@linutronix.de
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/Kconfig1
-rw-r--r--arch/mips/kernel/i8253.c97
2 files changed, 3 insertions, 95 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 45f7aacc0278..6cb60adb7b30 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2391,6 +2391,7 @@ config MMU
2391config I8253 2391config I8253
2392 bool 2392 bool
2393 select CLKSRC_I8253 2393 select CLKSRC_I8253
2394 select CLKEVT_I8253
2394 select MIPS_EXTERNAL_TIMER 2395 select MIPS_EXTERNAL_TIMER
2395 2396
2396config ZONE_DMA32 2397config ZONE_DMA32
diff --git a/arch/mips/kernel/i8253.c b/arch/mips/kernel/i8253.c
index 3d2ff57fa69a..8d95fe4f4871 100644
--- a/arch/mips/kernel/i8253.c
+++ b/arch/mips/kernel/i8253.c
@@ -4,92 +4,15 @@
4 */ 4 */
5#include <linux/clockchips.h> 5#include <linux/clockchips.h>
6#include <linux/i8253.h> 6#include <linux/i8253.h>
7#include <linux/init.h>
8#include <linux/interrupt.h>
9#include <linux/jiffies.h>
10#include <linux/module.h> 7#include <linux/module.h>
11#include <linux/smp.h> 8#include <linux/smp.h>
12#include <linux/spinlock.h>
13#include <linux/irq.h> 9#include <linux/irq.h>
14 10
15#include <asm/delay.h>
16#include <asm/io.h>
17#include <asm/time.h> 11#include <asm/time.h>
18 12
19/*
20 * Initialize the PIT timer.
21 *
22 * This is also called after resume to bring the PIT into operation again.
23 */
24static void init_pit_timer(enum clock_event_mode mode,
25 struct clock_event_device *evt)
26{
27 raw_spin_lock(&i8253_lock);
28
29 switch(mode) {
30 case CLOCK_EVT_MODE_PERIODIC:
31 /* binary, mode 2, LSB/MSB, ch 0 */
32 outb_p(0x34, PIT_MODE);
33 outb_p(LATCH & 0xff , PIT_CH0); /* LSB */
34 outb(LATCH >> 8 , PIT_CH0); /* MSB */
35 break;
36
37 case CLOCK_EVT_MODE_SHUTDOWN:
38 case CLOCK_EVT_MODE_UNUSED:
39 if (evt->mode == CLOCK_EVT_MODE_PERIODIC ||
40 evt->mode == CLOCK_EVT_MODE_ONESHOT) {
41 outb_p(0x30, PIT_MODE);
42 outb_p(0, PIT_CH0);
43 outb_p(0, PIT_CH0);
44 }
45 break;
46
47 case CLOCK_EVT_MODE_ONESHOT:
48 /* One shot setup */
49 outb_p(0x38, PIT_MODE);
50 break;
51
52 case CLOCK_EVT_MODE_RESUME:
53 /* Nothing to do here */
54 break;
55 }
56 raw_spin_unlock(&i8253_lock);
57}
58
59/*
60 * Program the next event in oneshot mode
61 *
62 * Delta is given in PIT ticks
63 */
64static int pit_next_event(unsigned long delta, struct clock_event_device *evt)
65{
66 raw_spin_lock(&i8253_lock);
67 outb_p(delta & 0xff , PIT_CH0); /* LSB */
68 outb(delta >> 8 , PIT_CH0); /* MSB */
69 raw_spin_unlock(&i8253_lock);
70
71 return 0;
72}
73
74/*
75 * On UP the PIT can serve all of the possible timer functions. On SMP systems
76 * it can be solely used for the global tick.
77 *
78 * The profiling and update capabilites are switched off once the local apic is
79 * registered. This mechanism replaces the previous #ifdef LOCAL_APIC -
80 * !using_apic_timer decisions in do_timer_interrupt_hook()
81 */
82static struct clock_event_device pit_clockevent = {
83 .name = "pit",
84 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
85 .set_mode = init_pit_timer,
86 .set_next_event = pit_next_event,
87 .irq = 0,
88};
89
90static irqreturn_t timer_interrupt(int irq, void *dev_id) 13static irqreturn_t timer_interrupt(int irq, void *dev_id)
91{ 14{
92 pit_clockevent.event_handler(&pit_clockevent); 15 i8253_clockevent.event_handler(&pit_clockevent);
93 16
94 return IRQ_HANDLED; 17 return IRQ_HANDLED;
95} 18}
@@ -100,25 +23,9 @@ static struct irqaction irq0 = {
100 .name = "timer" 23 .name = "timer"
101}; 24};
102 25
103/*
104 * Initialize the conversion factor and the min/max deltas of the clock event
105 * structure and register the clock event source with the framework.
106 */
107void __init setup_pit_timer(void) 26void __init setup_pit_timer(void)
108{ 27{
109 struct clock_event_device *cd = &pit_clockevent; 28 clockevent_i8253_init(true);
110 unsigned int cpu = smp_processor_id();
111
112 /*
113 * Start pit with the boot cpu mask and make it global after the
114 * IO_APIC has been initialized.
115 */
116 cd->cpumask = cpumask_of(cpu);
117 clockevent_set_clock(cd, CLOCK_TICK_RATE);
118 cd->max_delta_ns = clockevent_delta2ns(0x7FFF, cd);
119 cd->min_delta_ns = clockevent_delta2ns(0xF, cd);
120 clockevents_register_device(cd);
121
122 setup_irq(0, &irq0); 29 setup_irq(0, &irq0);
123} 30}
124 31