[PATCH v2 1/2] i8253: Add support for PIT shutdown quirk

From: Michael Kelley
Date: Sat Nov 03 2018 - 23:49:36 EST


Add support for platforms where pit_shutdown() doesn't work because
of a quirk in the PIT emulation. On these platforms setting the
counter register to zero causes the PIT to start running again,
negating the shutdown. Provide a global variable that controls
whether the counter register is zero'ed, which platform specific
code can override.

Signed-off-by: Michael Kelley <mikelley@xxxxxxxxxxxxx>
---
drivers/clocksource/i8253.c | 14 ++++++++++++--
include/linux/i8253.h | 1 +
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index 9c38895..2a4202a 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -20,6 +20,13 @@
DEFINE_RAW_SPINLOCK(i8253_lock);
EXPORT_SYMBOL(i8253_lock);

+/*
+ * Handle PIT quirk in pit_shutdown() where zeroing the counter register
+ * restarts the PIT, negating the shutdown. On platforms with the quirk,
+ * platform specific code can set this to false.
+ */
+bool i8253_clear_counter __ro_after_init = true;
+
#ifdef CONFIG_CLKSRC_I8253
/*
* Since the PIT overflows every tick, its not very useful
@@ -109,8 +116,11 @@ static int pit_shutdown(struct clock_event_device *evt)
raw_spin_lock(&i8253_lock);

outb_p(0x30, PIT_MODE);
- outb_p(0, PIT_CH0);
- outb_p(0, PIT_CH0);
+
+ if (i8253_clear_counter) {
+ outb_p(0, PIT_CH0);
+ outb_p(0, PIT_CH0);
+ }

raw_spin_unlock(&i8253_lock);
return 0;
diff --git a/include/linux/i8253.h b/include/linux/i8253.h
index e6bb36a..31c4be5 100644
--- a/include/linux/i8253.h
+++ b/include/linux/i8253.h
@@ -21,6 +21,7 @@
#define PIT_LATCH ((PIT_TICK_RATE + HZ/2) / HZ)

extern raw_spinlock_t i8253_lock;
+extern bool i8253_clear_counter;
extern struct clock_event_device i8253_clockevent;
extern void clockevent_i8253_init(bool oneshot);

--
1.8.3.1