aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-05-19 20:44:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-19 20:44:13 -0400
commit0f1bdc1815c4cb29b3cd71a7091b478e426faa0b (patch)
treeb4d70c6a305d91bf7d1c8a6bbf87508587d55633 /drivers
parent80fe02b5daf176f99d3afc8f6c9dc9dece019836 (diff)
parenta18f22a968de17b29f2310cdb7ba69163e65ec15 (diff)
Merge branch 'timers-clocksource-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'timers-clocksource-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: clocksource: convert mips to generic i8253 clocksource clocksource: convert x86 to generic i8253 clocksource clocksource: convert footbridge to generic i8253 clocksource clocksource: add common i8253 PIT clocksource blackfin: convert to clocksource_register_hz mips: convert to clocksource_register_hz/khz sparc: convert to clocksource_register_hz/khz alpha: convert to clocksource_register_hz microblaze: convert to clocksource_register_hz/khz ia64: convert to clocksource_register_hz/khz x86: Convert remaining x86 clocksources to clocksource_register_hz/khz Make clocksource name const
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig3
-rw-r--r--drivers/char/hpet.c6
-rw-r--r--drivers/clocksource/Kconfig2
-rw-r--r--drivers/clocksource/Makefile1
-rw-r--r--drivers/clocksource/cyclone.c10
-rw-r--r--drivers/clocksource/i8253.c88
6 files changed, 97 insertions, 13 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 177c7d156933..557a469c7aa6 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -119,4 +119,7 @@ source "drivers/platform/Kconfig"
119source "drivers/clk/Kconfig" 119source "drivers/clk/Kconfig"
120 120
121source "drivers/hwspinlock/Kconfig" 121source "drivers/hwspinlock/Kconfig"
122
123source "drivers/clocksource/Kconfig"
124
122endmenu 125endmenu
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 7066e801b9d3..051474c65b78 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -84,8 +84,6 @@ static struct clocksource clocksource_hpet = {
84 .rating = 250, 84 .rating = 250,
85 .read = read_hpet, 85 .read = read_hpet,
86 .mask = CLOCKSOURCE_MASK(64), 86 .mask = CLOCKSOURCE_MASK(64),
87 .mult = 0, /* to be calculated */
88 .shift = 10,
89 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 87 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
90}; 88};
91static struct clocksource *hpet_clocksource; 89static struct clocksource *hpet_clocksource;
@@ -934,9 +932,7 @@ int hpet_alloc(struct hpet_data *hdp)
934 if (!hpet_clocksource) { 932 if (!hpet_clocksource) {
935 hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc; 933 hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc;
936 CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr); 934 CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr);
937 clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq, 935 clocksource_register_hz(&clocksource_hpet, hpetp->hp_tick_freq);
938 clocksource_hpet.shift);
939 clocksource_register(&clocksource_hpet);
940 hpetp->hp_clocksource = &clocksource_hpet; 936 hpetp->hp_clocksource = &clocksource_hpet;
941 hpet_clocksource = &clocksource_hpet; 937 hpet_clocksource = &clocksource_hpet;
942 } 938 }
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 @@
1config 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
6obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o 6obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o
7obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o 7obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o
8obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o 8obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o
9obj-$(CONFIG_CLKSRC_I8253) += i8253.o
diff --git a/drivers/clocksource/cyclone.c b/drivers/clocksource/cyclone.c
index 64e528e8bfa6..72f811f73e9c 100644
--- a/drivers/clocksource/cyclone.c
+++ b/drivers/clocksource/cyclone.c
@@ -29,8 +29,6 @@ static struct clocksource clocksource_cyclone = {
29 .rating = 250, 29 .rating = 250,
30 .read = read_cyclone, 30 .read = read_cyclone,
31 .mask = CYCLONE_TIMER_MASK, 31 .mask = CYCLONE_TIMER_MASK,
32 .mult = 10,
33 .shift = 0,
34 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 32 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
35}; 33};
36 34
@@ -108,12 +106,8 @@ static int __init init_cyclone_clocksource(void)
108 } 106 }
109 cyclone_ptr = cyclone_timer; 107 cyclone_ptr = cyclone_timer;
110 108
111 /* sort out mult/shift values: */ 109 return clocksource_register_hz(&clocksource_cyclone,
112 clocksource_cyclone.shift = 22; 110 CYCLONE_TIMER_FREQ);
113 clocksource_cyclone.mult = clocksource_hz2mult(CYCLONE_TIMER_FREQ,
114 clocksource_cyclone.shift);
115
116 return clocksource_register(&clocksource_cyclone);
117} 111}
118 112
119arch_initcall(init_cyclone_clocksource); 113arch_initcall(init_cyclone_clocksource);
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 */
17static 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
78static struct clocksource i8253_cs = {
79 .name = "pit",
80 .rating = 110,
81 .read = i8253_read,
82 .mask = CLOCKSOURCE_MASK(32),
83};
84
85int __init clocksource_i8253_init(void)
86{
87 return clocksource_register_hz(&i8253_cs, PIT_TICK_RATE);
88}