Full support for Ginger Console
[linux-ginger.git] / arch / x86 / kernel / pmtimer_64.c
blobb112406f19961932f1505aeafa09d402a2ca45b1
1 /* Ported over from i386 by AK, original copyright was:
3 * (C) Dominik Brodowski <linux@brodo.de> 2003
5 * Driver to use the Power Management Timer (PMTMR) available in some
6 * southbridges as primary timing source for the Linux kernel.
8 * Based on parts of linux/drivers/acpi/hardware/hwtimer.c, timer_pit.c,
9 * timer_hpet.c, and on Arjan van de Ven's implementation for 2.4.
11 * This file is licensed under the GPL v2.
13 * Dropped all the hardware bug workarounds for now. Hopefully they
14 * are not needed on 64bit chipsets.
17 #include <linux/jiffies.h>
18 #include <linux/kernel.h>
19 #include <linux/time.h>
20 #include <linux/init.h>
21 #include <linux/cpumask.h>
22 #include <linux/acpi_pmtmr.h>
24 #include <asm/io.h>
25 #include <asm/proto.h>
26 #include <asm/msr.h>
27 #include <asm/vsyscall.h>
29 static inline u32 cyc2us(u32 cycles)
31 /* The Power Management Timer ticks at 3.579545 ticks per microsecond.
32 * 1 / PM_TIMER_FREQUENCY == 0.27936511 =~ 286/1024 [error: 0.024%]
34 * Even with HZ = 100, delta is at maximum 35796 ticks, so it can
35 * easily be multiplied with 286 (=0x11E) without having to fear
36 * u32 overflows.
38 cycles *= 286;
39 return (cycles >> 10);
42 static unsigned pmtimer_wait_tick(void)
44 u32 a, b;
45 for (a = b = inl(pmtmr_ioport) & ACPI_PM_MASK;
46 a == b;
47 b = inl(pmtmr_ioport) & ACPI_PM_MASK)
48 cpu_relax();
49 return b;
52 /* note: wait time is rounded up to one tick */
53 void pmtimer_wait(unsigned us)
55 u32 a, b;
56 a = pmtimer_wait_tick();
57 do {
58 b = inl(pmtmr_ioport);
59 cpu_relax();
60 } while (cyc2us(b - a) < us);
63 static int __init nopmtimer_setup(char *s)
65 pmtmr_ioport = 0;
66 return 1;
69 __setup("nopmtimer", nopmtimer_setup);