diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2011-05-14 06:06:36 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2011-05-14 06:06:36 -0400 |
| commit | a18f22a968de17b29f2310cdb7ba69163e65ec15 (patch) | |
| tree | a7d56d88fad5e444d7661484109758a2f436129e /drivers/clocksource | |
| parent | a1c57e0fec53defe745e64417eacdbd3618c3e66 (diff) | |
| parent | 798778b8653f64b7b2162ac70eca10367cff6ce8 (diff) | |
Merge branch 'consolidate-clksrc-i8253' of master.kernel.org:~rmk/linux-2.6-arm into timers/clocksource
Conflicts:
arch/ia64/kernel/cyclone.c
arch/mips/kernel/i8253.c
arch/x86/kernel/i8253.c
Reason: Resolve conflicts so further cleanups do not conflict further
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/clocksource')
| -rw-r--r-- | drivers/clocksource/Kconfig | 2 | ||||
| -rw-r--r-- | drivers/clocksource/Makefile | 1 | ||||
| -rw-r--r-- | drivers/clocksource/i8253.c | 88 |
3 files changed, 91 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig new file mode 100644 index 000000000000..110aeeb52f9a --- /dev/null +++ b/drivers/clocksource/Kconfig | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | config CLKSRC_I8253 | ||
| 2 | bool | ||
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index be61ece6330b..cfb6383b543a 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
| @@ -6,3 +6,4 @@ obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o | |||
| 6 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o | 6 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o |
| 7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o | 7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o |
| 8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o | 8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o |
| 9 | obj-$(CONFIG_CLKSRC_I8253) += i8253.o | ||
diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c new file mode 100644 index 000000000000..225c1761b372 --- /dev/null +++ b/drivers/clocksource/i8253.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* | ||
| 2 | * i8253 PIT clocksource | ||
| 3 | */ | ||
| 4 | #include <linux/clocksource.h> | ||
| 5 | #include <linux/init.h> | ||
| 6 | #include <linux/io.h> | ||
| 7 | #include <linux/spinlock.h> | ||
| 8 | #include <linux/timex.h> | ||
| 9 | |||
| 10 | #include <asm/i8253.h> | ||
| 11 | |||
| 12 | /* | ||
| 13 | * Since the PIT overflows every tick, its not very useful | ||
| 14 | * to just read by itself. So use jiffies to emulate a free | ||
| 15 | * running counter: | ||
| 16 | */ | ||
| 17 | static cycle_t i8253_read(struct clocksource *cs) | ||
| 18 | { | ||
| 19 | static int old_count; | ||
| 20 | static u32 old_jifs; | ||
| 21 | unsigned long flags; | ||
| 22 | int count; | ||
| 23 | u32 jifs; | ||
| 24 | |||
| 25 | raw_spin_lock_irqsave(&i8253_lock, flags); | ||
| 26 | /* | ||
| 27 | * Although our caller may have the read side of xtime_lock, | ||
| 28 | * this is now a seqlock, and we are cheating in this routine | ||
| 29 | * by having side effects on state that we cannot undo if | ||
| 30 | * there is a collision on the seqlock and our caller has to | ||
| 31 | * retry. (Namely, old_jifs and old_count.) So we must treat | ||
| 32 | * jiffies as volatile despite the lock. We read jiffies | ||
| 33 | * before latching the timer count to guarantee that although | ||
| 34 | * the jiffies value might be older than the count (that is, | ||
| 35 | * the counter may underflow between the last point where | ||
| 36 | * jiffies was incremented and the point where we latch the | ||
| 37 | * count), it cannot be newer. | ||
| 38 | */ | ||
| 39 | jifs = jiffies; | ||
| 40 | outb_pit(0x00, PIT_MODE); /* latch the count ASAP */ | ||
| 41 | count = inb_pit(PIT_CH0); /* read the latched count */ | ||
| 42 | count |= inb_pit(PIT_CH0) << 8; | ||
| 43 | |||
| 44 | /* VIA686a test code... reset the latch if count > max + 1 */ | ||
| 45 | if (count > LATCH) { | ||
| 46 | outb_pit(0x34, PIT_MODE); | ||
| 47 | outb_pit(PIT_LATCH & 0xff, PIT_CH0); | ||
| 48 | outb_pit(PIT_LATCH >> 8, PIT_CH0); | ||
| 49 | count = PIT_LATCH - 1; | ||
| 50 | } | ||
| 51 | |||
| 52 | /* | ||
| 53 | * It's possible for count to appear to go the wrong way for a | ||
| 54 | * couple of reasons: | ||
| 55 | * | ||
| 56 | * 1. The timer counter underflows, but we haven't handled the | ||
| 57 | * resulting interrupt and incremented jiffies yet. | ||
| 58 | * 2. Hardware problem with the timer, not giving us continuous time, | ||
| 59 | * the counter does small "jumps" upwards on some Pentium systems, | ||
| 60 | * (see c't 95/10 page 335 for Neptun bug.) | ||
| 61 | * | ||
| 62 | * Previous attempts to handle these cases intelligently were | ||
| 63 | * buggy, so we just do the simple thing now. | ||
| 64 | */ | ||
| 65 | if (count > old_count && jifs == old_jifs) | ||
| 66 | count = old_count; | ||
| 67 | |||
| 68 | old_count = count; | ||
| 69 | old_jifs = jifs; | ||
| 70 | |||
| 71 | raw_spin_unlock_irqrestore(&i8253_lock, flags); | ||
| 72 | |||
| 73 | count = (PIT_LATCH - 1) - count; | ||
| 74 | |||
| 75 | return (cycle_t)(jifs * PIT_LATCH) + count; | ||
| 76 | } | ||
| 77 | |||
| 78 | static struct clocksource i8253_cs = { | ||
| 79 | .name = "pit", | ||
| 80 | .rating = 110, | ||
| 81 | .read = i8253_read, | ||
| 82 | .mask = CLOCKSOURCE_MASK(32), | ||
| 83 | }; | ||
| 84 | |||
| 85 | int __init clocksource_i8253_init(void) | ||
| 86 | { | ||
| 87 | return clocksource_register_hz(&i8253_cs, PIT_TICK_RATE); | ||
| 88 | } | ||
