aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/clocksource/Kconfig5
-rw-r--r--drivers/clocksource/i8253.c101
-rw-r--r--include/linux/i8253.h2
3 files changed, 100 insertions, 8 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 330343bcb67e..d8d3e02b912c 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -1,11 +1,14 @@
1config CLKSRC_I8253 1config CLKSRC_I8253
2 bool 2 bool
3 3
4config CLKEVT_I8253
5 bool
6
4config I8253_LOCK 7config I8253_LOCK
5 bool 8 bool
6 9
7config CLKBLD_I8253 10config CLKBLD_I8253
8 def_bool y if CLKSRC_I8253 || I8253_LOCK 11 def_bool y if CLKSRC_I8253 || CLKEVT_I8253 || I8253_LOCK
9 12
10config CLKSRC_MMIO 13config CLKSRC_MMIO
11 bool 14 bool
diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index e594f52eb88e..27c49e60b7d6 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -1,13 +1,14 @@
1/* 1/*
2 * i8253 PIT clocksource 2 * i8253 PIT clocksource
3 */ 3 */
4#include <linux/clocksource.h> 4#include <linux/clockchips.h>
5#include <linux/init.h> 5#include <linux/init.h>
6#include <linux/io.h> 6#include <linux/io.h>
7#include <linux/spinlock.h> 7#include <linux/spinlock.h>
8#include <linux/timex.h> 8#include <linux/timex.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/i8253.h> 10#include <linux/i8253.h>
11#include <linux/smp.h>
11 12
12/* 13/*
13 * Protects access to I/O ports 14 * Protects access to I/O ports
@@ -47,15 +48,15 @@ static cycle_t i8253_read(struct clocksource *cs)
47 * count), it cannot be newer. 48 * count), it cannot be newer.
48 */ 49 */
49 jifs = jiffies; 50 jifs = jiffies;
50 outb_pit(0x00, PIT_MODE); /* latch the count ASAP */ 51 outb_p(0x00, PIT_MODE); /* latch the count ASAP */
51 count = inb_pit(PIT_CH0); /* read the latched count */ 52 count = inb_p(PIT_CH0); /* read the latched count */
52 count |= inb_pit(PIT_CH0) << 8; 53 count |= inb_p(PIT_CH0) << 8;
53 54
54 /* VIA686a test code... reset the latch if count > max + 1 */ 55 /* VIA686a test code... reset the latch if count > max + 1 */
55 if (count > LATCH) { 56 if (count > LATCH) {
56 outb_pit(0x34, PIT_MODE); 57 outb_p(0x34, PIT_MODE);
57 outb_pit(PIT_LATCH & 0xff, PIT_CH0); 58 outb_p(PIT_LATCH & 0xff, PIT_CH0);
58 outb_pit(PIT_LATCH >> 8, PIT_CH0); 59 outb_p(PIT_LATCH >> 8, PIT_CH0);
59 count = PIT_LATCH - 1; 60 count = PIT_LATCH - 1;
60 } 61 }
61 62
@@ -97,3 +98,89 @@ int __init clocksource_i8253_init(void)
97 return clocksource_register_hz(&i8253_cs, PIT_TICK_RATE); 98 return clocksource_register_hz(&i8253_cs, PIT_TICK_RATE);
98} 99}
99#endif 100#endif
101
102#ifdef CONFIG_CLKEVT_I8253
103/*
104 * Initialize the PIT timer.
105 *
106 * This is also called after resume to bring the PIT into operation again.
107 */
108static void init_pit_timer(enum clock_event_mode mode,
109 struct clock_event_device *evt)
110{
111 raw_spin_lock(&i8253_lock);
112
113 switch (mode) {
114 case CLOCK_EVT_MODE_PERIODIC:
115 /* binary, mode 2, LSB/MSB, ch 0 */
116 outb_p(0x34, PIT_MODE);
117 outb_p(LATCH & 0xff , PIT_CH0); /* LSB */
118 outb_p(LATCH >> 8 , PIT_CH0); /* MSB */
119 break;
120
121 case CLOCK_EVT_MODE_SHUTDOWN:
122 case CLOCK_EVT_MODE_UNUSED:
123 if (evt->mode == CLOCK_EVT_MODE_PERIODIC ||
124 evt->mode == CLOCK_EVT_MODE_ONESHOT) {
125 outb_p(0x30, PIT_MODE);
126 outb_p(0, PIT_CH0);
127 outb_p(0, PIT_CH0);
128 }
129 break;
130
131 case CLOCK_EVT_MODE_ONESHOT:
132 /* One shot setup */
133 outb_p(0x38, PIT_MODE);
134 break;
135
136 case CLOCK_EVT_MODE_RESUME:
137 /* Nothing to do here */
138 break;
139 }
140 raw_spin_unlock(&i8253_lock);
141}
142
143/*
144 * Program the next event in oneshot mode
145 *
146 * Delta is given in PIT ticks
147 */
148static int pit_next_event(unsigned long delta, struct clock_event_device *evt)
149{
150 raw_spin_lock(&i8253_lock);
151 outb_p(delta & 0xff , PIT_CH0); /* LSB */
152 outb_p(delta >> 8 , PIT_CH0); /* MSB */
153 raw_spin_unlock(&i8253_lock);
154
155 return 0;
156}
157
158/*
159 * On UP the PIT can serve all of the possible timer functions. On SMP systems
160 * it can be solely used for the global tick.
161 */
162struct clock_event_device i8253_clockevent = {
163 .name = "pit",
164 .features = CLOCK_EVT_FEAT_PERIODIC,
165 .set_mode = init_pit_timer,
166 .set_next_event = pit_next_event,
167};
168
169/*
170 * Initialize the conversion factor and the min/max deltas of the clock event
171 * structure and register the clock event source with the framework.
172 */
173void __init clockevent_i8253_init(bool oneshot)
174{
175 if (oneshot)
176 i8253_clockevent.features |= CLOCK_EVT_FEAT_ONESHOT;
177 /*
178 * Start pit with the boot cpu mask. x86 might make it global
179 * when it is used as broadcast device later.
180 */
181 i8253_clockevent.cpumask = cpumask_of(smp_processor_id());
182
183 clockevents_config_and_register(&i8253_clockevent, PIT_TICK_RATE,
184 0xF, 0x7FFF);
185}
186#endif
diff --git a/include/linux/i8253.h b/include/linux/i8253.h
index 76039c86ab58..487d50c7db39 100644
--- a/include/linux/i8253.h
+++ b/include/linux/i8253.h
@@ -24,6 +24,8 @@
24#define outb_pit outb_p 24#define outb_pit outb_p
25 25
26extern raw_spinlock_t i8253_lock; 26extern raw_spinlock_t i8253_lock;
27extern struct clock_event_device i8253_clockevent;
28extern void clockevent_i8253_init(bool oneshot);
27 29
28extern void setup_pit_timer(void); 30extern void setup_pit_timer(void);
29 31