john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 1 | #include <linux/clocksource.h> |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 2 | #include <linux/clockchips.h> |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 3 | #include <linux/interrupt.h> |
| 4 | #include <linux/sysdev.h> |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 5 | #include <linux/delay.h> |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 6 | #include <linux/errno.h> |
| 7 | #include <linux/hpet.h> |
| 8 | #include <linux/init.h> |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 9 | #include <linux/cpu.h> |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 10 | #include <linux/pm.h> |
| 11 | #include <linux/io.h> |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 12 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 13 | #include <asm/fixmap.h> |
Thomas Gleixner | 06a24de | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 14 | #include <asm/i8253.h> |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 15 | #include <asm/hpet.h> |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 16 | |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 17 | #define HPET_MASK CLOCKSOURCE_MASK(32) |
| 18 | #define HPET_SHIFT 22 |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 19 | |
Pavel Machek | b10db7f | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 20 | /* FSEC = 10^-15 |
| 21 | NSEC = 10^-9 */ |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 22 | #define FSEC_PER_NSEC 1000000L |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 23 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 24 | #define HPET_DEV_USED_BIT 2 |
| 25 | #define HPET_DEV_USED (1 << HPET_DEV_USED_BIT) |
| 26 | #define HPET_DEV_VALID 0x8 |
| 27 | #define HPET_DEV_FSB_CAP 0x1000 |
| 28 | #define HPET_DEV_PERI_CAP 0x2000 |
| 29 | |
| 30 | #define EVT_TO_HPET_DEV(evt) container_of(evt, struct hpet_dev, evt) |
| 31 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 32 | /* |
| 33 | * HPET address is set in acpi/boot.c, when an ACPI entry exists |
| 34 | */ |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 35 | unsigned long hpet_address; |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 36 | unsigned long hpet_num_timers; |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 37 | static void __iomem *hpet_virt_address; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 38 | |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 39 | struct hpet_dev { |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 40 | struct clock_event_device evt; |
| 41 | unsigned int num; |
| 42 | int cpu; |
| 43 | unsigned int irq; |
| 44 | unsigned int flags; |
| 45 | char name[10]; |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
Chris Wright | 31c435d | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 48 | unsigned long hpet_readl(unsigned long a) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 49 | { |
| 50 | return readl(hpet_virt_address + a); |
| 51 | } |
| 52 | |
| 53 | static inline void hpet_writel(unsigned long d, unsigned long a) |
| 54 | { |
| 55 | writel(d, hpet_virt_address + a); |
| 56 | } |
| 57 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_X86_64 |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 59 | #include <asm/pgtable.h> |
Yinghai Lu | 2387ce5 | 2008-07-13 14:50:56 -0700 | [diff] [blame] | 60 | #endif |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 61 | |
Thomas Gleixner | 06a24de | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 62 | static inline void hpet_set_mapping(void) |
| 63 | { |
| 64 | hpet_virt_address = ioremap_nocache(hpet_address, HPET_MMAP_SIZE); |
Yinghai Lu | 2387ce5 | 2008-07-13 14:50:56 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_X86_64 |
| 66 | __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE); |
| 67 | #endif |
Thomas Gleixner | 06a24de | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline void hpet_clear_mapping(void) |
| 71 | { |
| 72 | iounmap(hpet_virt_address); |
| 73 | hpet_virt_address = NULL; |
| 74 | } |
| 75 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 76 | /* |
| 77 | * HPET command line enable / disable |
| 78 | */ |
| 79 | static int boot_hpet_disable; |
Thomas Gleixner | b17530b | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 80 | int hpet_force_user; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 81 | |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 82 | static int __init hpet_setup(char *str) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 83 | { |
| 84 | if (str) { |
| 85 | if (!strncmp("disable", str, 7)) |
| 86 | boot_hpet_disable = 1; |
Thomas Gleixner | b17530b | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 87 | if (!strncmp("force", str, 5)) |
| 88 | hpet_force_user = 1; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 89 | } |
| 90 | return 1; |
| 91 | } |
| 92 | __setup("hpet=", hpet_setup); |
| 93 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 94 | static int __init disable_hpet(char *str) |
| 95 | { |
| 96 | boot_hpet_disable = 1; |
| 97 | return 1; |
| 98 | } |
| 99 | __setup("nohpet", disable_hpet); |
| 100 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 101 | static inline int is_hpet_capable(void) |
| 102 | { |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 103 | return !boot_hpet_disable && hpet_address; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
| 107 | * HPET timer interrupt enable / disable |
| 108 | */ |
| 109 | static int hpet_legacy_int_enabled; |
| 110 | |
| 111 | /** |
| 112 | * is_hpet_enabled - check whether the hpet timer interrupt is enabled |
| 113 | */ |
| 114 | int is_hpet_enabled(void) |
| 115 | { |
| 116 | return is_hpet_capable() && hpet_legacy_int_enabled; |
| 117 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 118 | EXPORT_SYMBOL_GPL(is_hpet_enabled); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * When the hpet driver (/dev/hpet) is enabled, we need to reserve |
| 122 | * timer 0 and timer 1 in case of RTC emulation. |
| 123 | */ |
| 124 | #ifdef CONFIG_HPET |
Venki Pallipadi | f0ed4e6 | 2008-09-08 10:18:40 -0700 | [diff] [blame] | 125 | |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 126 | static void hpet_reserve_msi_timers(struct hpet_data *hd); |
Venki Pallipadi | f0ed4e6 | 2008-09-08 10:18:40 -0700 | [diff] [blame] | 127 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 128 | static void hpet_reserve_platform_timers(unsigned long id) |
| 129 | { |
| 130 | struct hpet __iomem *hpet = hpet_virt_address; |
Balaji Rao | 37a47db8 | 2008-01-30 13:30:03 +0100 | [diff] [blame] | 131 | struct hpet_timer __iomem *timer = &hpet->hpet_timers[2]; |
| 132 | unsigned int nrtimers, i; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 133 | struct hpet_data hd; |
| 134 | |
| 135 | nrtimers = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT) + 1; |
| 136 | |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 137 | memset(&hd, 0, sizeof(hd)); |
| 138 | hd.hd_phys_address = hpet_address; |
| 139 | hd.hd_address = hpet; |
| 140 | hd.hd_nirqs = nrtimers; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 141 | hpet_reserve_timer(&hd, 0); |
| 142 | |
| 143 | #ifdef CONFIG_HPET_EMULATE_RTC |
| 144 | hpet_reserve_timer(&hd, 1); |
| 145 | #endif |
Thomas Gleixner | 5761d64 | 2008-04-04 16:26:10 +0200 | [diff] [blame] | 146 | |
David Brownell | 64a76f6 | 2008-07-29 12:47:38 -0700 | [diff] [blame] | 147 | /* |
| 148 | * NOTE that hd_irq[] reflects IOAPIC input pins (LEGACY_8254 |
| 149 | * is wrong for i8259!) not the output IRQ. Many BIOS writers |
| 150 | * don't bother configuring *any* comparator interrupts. |
| 151 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 152 | hd.hd_irq[0] = HPET_LEGACY_8254; |
| 153 | hd.hd_irq[1] = HPET_LEGACY_RTC; |
| 154 | |
Ingo Molnar | fc3fbc4 | 2008-04-27 14:04:14 +0200 | [diff] [blame] | 155 | for (i = 2; i < nrtimers; timer++, i++) { |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 156 | hd.hd_irq[i] = (readl(&timer->hpet_config) & |
| 157 | Tn_INT_ROUTE_CNF_MASK) >> Tn_INT_ROUTE_CNF_SHIFT; |
Ingo Molnar | fc3fbc4 | 2008-04-27 14:04:14 +0200 | [diff] [blame] | 158 | } |
Thomas Gleixner | 5761d64 | 2008-04-04 16:26:10 +0200 | [diff] [blame] | 159 | |
Venki Pallipadi | f0ed4e6 | 2008-09-08 10:18:40 -0700 | [diff] [blame] | 160 | hpet_reserve_msi_timers(&hd); |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 161 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 162 | hpet_alloc(&hd); |
Thomas Gleixner | 5761d64 | 2008-04-04 16:26:10 +0200 | [diff] [blame] | 163 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 164 | } |
| 165 | #else |
| 166 | static void hpet_reserve_platform_timers(unsigned long id) { } |
| 167 | #endif |
| 168 | |
| 169 | /* |
| 170 | * Common hpet info |
| 171 | */ |
| 172 | static unsigned long hpet_period; |
| 173 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 174 | static void hpet_legacy_set_mode(enum clock_event_mode mode, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 175 | struct clock_event_device *evt); |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 176 | static int hpet_legacy_next_event(unsigned long delta, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 177 | struct clock_event_device *evt); |
| 178 | |
| 179 | /* |
| 180 | * The hpet clock event device |
| 181 | */ |
| 182 | static struct clock_event_device hpet_clockevent = { |
| 183 | .name = "hpet", |
| 184 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 185 | .set_mode = hpet_legacy_set_mode, |
| 186 | .set_next_event = hpet_legacy_next_event, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 187 | .shift = 32, |
| 188 | .irq = 0, |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 189 | .rating = 50, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | static void hpet_start_counter(void) |
| 193 | { |
| 194 | unsigned long cfg = hpet_readl(HPET_CFG); |
| 195 | |
| 196 | cfg &= ~HPET_CFG_ENABLE; |
| 197 | hpet_writel(cfg, HPET_CFG); |
| 198 | hpet_writel(0, HPET_COUNTER); |
| 199 | hpet_writel(0, HPET_COUNTER + 4); |
| 200 | cfg |= HPET_CFG_ENABLE; |
| 201 | hpet_writel(cfg, HPET_CFG); |
| 202 | } |
| 203 | |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 204 | static void hpet_resume_device(void) |
| 205 | { |
Venki Pallipadi | bfe0c1c | 2007-10-12 23:04:24 +0200 | [diff] [blame] | 206 | force_hpet_resume(); |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void hpet_restart_counter(void) |
| 210 | { |
| 211 | hpet_resume_device(); |
| 212 | hpet_start_counter(); |
| 213 | } |
| 214 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 215 | static void hpet_enable_legacy_int(void) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 216 | { |
| 217 | unsigned long cfg = hpet_readl(HPET_CFG); |
| 218 | |
| 219 | cfg |= HPET_CFG_LEGACY; |
| 220 | hpet_writel(cfg, HPET_CFG); |
| 221 | hpet_legacy_int_enabled = 1; |
| 222 | } |
| 223 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 224 | static void hpet_legacy_clockevent_register(void) |
| 225 | { |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 226 | /* Start HPET legacy interrupts */ |
| 227 | hpet_enable_legacy_int(); |
| 228 | |
| 229 | /* |
Carlos R. Mafra | 6fd592d | 2008-05-05 20:11:22 -0300 | [diff] [blame] | 230 | * The mult factor is defined as (include/linux/clockchips.h) |
| 231 | * mult/2^shift = cyc/ns (in contrast to ns/cyc in clocksource.h) |
| 232 | * hpet_period is in units of femtoseconds (per cycle), so |
| 233 | * mult/2^shift = cyc/ns = 10^6/hpet_period |
| 234 | * mult = (10^6 * 2^shift)/hpet_period |
| 235 | * mult = (FSEC_PER_NSEC << hpet_clockevent.shift)/hpet_period |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 236 | */ |
Carlos R. Mafra | 6fd592d | 2008-05-05 20:11:22 -0300 | [diff] [blame] | 237 | hpet_clockevent.mult = div_sc((unsigned long) FSEC_PER_NSEC, |
| 238 | hpet_period, hpet_clockevent.shift); |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 239 | /* Calculate the min / max delta */ |
| 240 | hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF, |
| 241 | &hpet_clockevent); |
Thomas Gleixner | 7cfb0435 | 2008-09-03 21:37:24 +0000 | [diff] [blame] | 242 | /* 5 usec minimum reprogramming delta. */ |
| 243 | hpet_clockevent.min_delta_ns = 5000; |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Start hpet with the boot cpu mask and make it |
| 247 | * global after the IO_APIC has been initialized. |
| 248 | */ |
| 249 | hpet_clockevent.cpumask = cpumask_of_cpu(smp_processor_id()); |
| 250 | clockevents_register_device(&hpet_clockevent); |
| 251 | global_clock_event = &hpet_clockevent; |
| 252 | printk(KERN_DEBUG "hpet clockevent registered\n"); |
| 253 | } |
| 254 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 255 | static int hpet_setup_msi_irq(unsigned int irq); |
| 256 | |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 257 | static void hpet_set_mode(enum clock_event_mode mode, |
| 258 | struct clock_event_device *evt, int timer) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 259 | { |
| 260 | unsigned long cfg, cmp, now; |
| 261 | uint64_t delta; |
| 262 | |
Ingo Molnar | 4588c1f | 2008-09-06 14:19:17 +0200 | [diff] [blame] | 263 | switch (mode) { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 264 | case CLOCK_EVT_MODE_PERIODIC: |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 265 | delta = ((uint64_t)(NSEC_PER_SEC/HZ)) * evt->mult; |
| 266 | delta >>= evt->shift; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 267 | now = hpet_readl(HPET_COUNTER); |
| 268 | cmp = now + (unsigned long) delta; |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 269 | cfg = hpet_readl(HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 270 | cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | |
| 271 | HPET_TN_SETVAL | HPET_TN_32BIT; |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 272 | hpet_writel(cfg, HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 273 | /* |
| 274 | * The first write after writing TN_SETVAL to the |
| 275 | * config register sets the counter value, the second |
| 276 | * write sets the period. |
| 277 | */ |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 278 | hpet_writel(cmp, HPET_Tn_CMP(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 279 | udelay(1); |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 280 | hpet_writel((unsigned long) delta, HPET_Tn_CMP(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 281 | break; |
| 282 | |
| 283 | case CLOCK_EVT_MODE_ONESHOT: |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 284 | cfg = hpet_readl(HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 285 | cfg &= ~HPET_TN_PERIODIC; |
| 286 | cfg |= HPET_TN_ENABLE | HPET_TN_32BIT; |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 287 | hpet_writel(cfg, HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 288 | break; |
| 289 | |
| 290 | case CLOCK_EVT_MODE_UNUSED: |
| 291 | case CLOCK_EVT_MODE_SHUTDOWN: |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 292 | cfg = hpet_readl(HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 293 | cfg &= ~HPET_TN_ENABLE; |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 294 | hpet_writel(cfg, HPET_Tn_CFG(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 295 | break; |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 296 | |
| 297 | case CLOCK_EVT_MODE_RESUME: |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 298 | if (timer == 0) { |
| 299 | hpet_enable_legacy_int(); |
| 300 | } else { |
| 301 | struct hpet_dev *hdev = EVT_TO_HPET_DEV(evt); |
| 302 | hpet_setup_msi_irq(hdev->irq); |
| 303 | disable_irq(hdev->irq); |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame^] | 304 | irq_set_affinity(hdev->irq, cpumask_of(hdev->cpu)); |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 305 | enable_irq(hdev->irq); |
| 306 | } |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 307 | break; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 311 | static int hpet_next_event(unsigned long delta, |
| 312 | struct clock_event_device *evt, int timer) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 313 | { |
Thomas Gleixner | f767625 | 2008-09-06 03:03:32 +0200 | [diff] [blame] | 314 | u32 cnt; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 315 | |
| 316 | cnt = hpet_readl(HPET_COUNTER); |
Thomas Gleixner | f767625 | 2008-09-06 03:03:32 +0200 | [diff] [blame] | 317 | cnt += (u32) delta; |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 318 | hpet_writel(cnt, HPET_Tn_CMP(timer)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 319 | |
Thomas Gleixner | 72d43d9 | 2008-09-06 03:06:08 +0200 | [diff] [blame] | 320 | /* |
| 321 | * We need to read back the CMP register to make sure that |
| 322 | * what we wrote hit the chip before we compare it to the |
| 323 | * counter. |
| 324 | */ |
Matt Fleming | 89d77a1 | 2008-11-02 16:04:20 +0000 | [diff] [blame] | 325 | WARN_ON_ONCE((u32)hpet_readl(HPET_Tn_CMP(timer)) != cnt); |
Thomas Gleixner | 72d43d9 | 2008-09-06 03:06:08 +0200 | [diff] [blame] | 326 | |
Thomas Gleixner | f767625 | 2008-09-06 03:03:32 +0200 | [diff] [blame] | 327 | return (s32)((u32)hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 328 | } |
| 329 | |
venkatesh.pallipadi@intel.com | b40d575 | 2008-09-05 18:02:16 -0700 | [diff] [blame] | 330 | static void hpet_legacy_set_mode(enum clock_event_mode mode, |
| 331 | struct clock_event_device *evt) |
| 332 | { |
| 333 | hpet_set_mode(mode, evt, 0); |
| 334 | } |
| 335 | |
| 336 | static int hpet_legacy_next_event(unsigned long delta, |
| 337 | struct clock_event_device *evt) |
| 338 | { |
| 339 | return hpet_next_event(delta, evt, 0); |
| 340 | } |
| 341 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 342 | /* |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 343 | * HPET MSI Support |
| 344 | */ |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 345 | #ifdef CONFIG_PCI_MSI |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 346 | |
| 347 | static DEFINE_PER_CPU(struct hpet_dev *, cpu_hpet_dev); |
| 348 | static struct hpet_dev *hpet_devs; |
| 349 | |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 350 | void hpet_msi_unmask(unsigned int irq) |
| 351 | { |
| 352 | struct hpet_dev *hdev = get_irq_data(irq); |
| 353 | unsigned long cfg; |
| 354 | |
| 355 | /* unmask it */ |
| 356 | cfg = hpet_readl(HPET_Tn_CFG(hdev->num)); |
| 357 | cfg |= HPET_TN_FSB; |
| 358 | hpet_writel(cfg, HPET_Tn_CFG(hdev->num)); |
| 359 | } |
| 360 | |
| 361 | void hpet_msi_mask(unsigned int irq) |
| 362 | { |
| 363 | unsigned long cfg; |
| 364 | struct hpet_dev *hdev = get_irq_data(irq); |
| 365 | |
| 366 | /* mask it */ |
| 367 | cfg = hpet_readl(HPET_Tn_CFG(hdev->num)); |
| 368 | cfg &= ~HPET_TN_FSB; |
| 369 | hpet_writel(cfg, HPET_Tn_CFG(hdev->num)); |
| 370 | } |
| 371 | |
| 372 | void hpet_msi_write(unsigned int irq, struct msi_msg *msg) |
| 373 | { |
| 374 | struct hpet_dev *hdev = get_irq_data(irq); |
| 375 | |
| 376 | hpet_writel(msg->data, HPET_Tn_ROUTE(hdev->num)); |
| 377 | hpet_writel(msg->address_lo, HPET_Tn_ROUTE(hdev->num) + 4); |
| 378 | } |
| 379 | |
| 380 | void hpet_msi_read(unsigned int irq, struct msi_msg *msg) |
| 381 | { |
| 382 | struct hpet_dev *hdev = get_irq_data(irq); |
| 383 | |
| 384 | msg->data = hpet_readl(HPET_Tn_ROUTE(hdev->num)); |
| 385 | msg->address_lo = hpet_readl(HPET_Tn_ROUTE(hdev->num) + 4); |
| 386 | msg->address_hi = 0; |
| 387 | } |
| 388 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 389 | static void hpet_msi_set_mode(enum clock_event_mode mode, |
| 390 | struct clock_event_device *evt) |
| 391 | { |
| 392 | struct hpet_dev *hdev = EVT_TO_HPET_DEV(evt); |
| 393 | hpet_set_mode(mode, evt, hdev->num); |
| 394 | } |
| 395 | |
| 396 | static int hpet_msi_next_event(unsigned long delta, |
| 397 | struct clock_event_device *evt) |
| 398 | { |
| 399 | struct hpet_dev *hdev = EVT_TO_HPET_DEV(evt); |
| 400 | return hpet_next_event(delta, evt, hdev->num); |
| 401 | } |
| 402 | |
| 403 | static int hpet_setup_msi_irq(unsigned int irq) |
| 404 | { |
| 405 | if (arch_setup_hpet_msi(irq)) { |
| 406 | destroy_irq(irq); |
| 407 | return -EINVAL; |
| 408 | } |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int hpet_assign_irq(struct hpet_dev *dev) |
| 413 | { |
| 414 | unsigned int irq; |
| 415 | |
| 416 | irq = create_irq(); |
| 417 | if (!irq) |
| 418 | return -EINVAL; |
| 419 | |
| 420 | set_irq_data(irq, dev); |
| 421 | |
| 422 | if (hpet_setup_msi_irq(irq)) |
| 423 | return -EINVAL; |
| 424 | |
| 425 | dev->irq = irq; |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static irqreturn_t hpet_interrupt_handler(int irq, void *data) |
| 430 | { |
| 431 | struct hpet_dev *dev = (struct hpet_dev *)data; |
| 432 | struct clock_event_device *hevt = &dev->evt; |
| 433 | |
| 434 | if (!hevt->event_handler) { |
| 435 | printk(KERN_INFO "Spurious HPET timer interrupt on HPET timer %d\n", |
| 436 | dev->num); |
| 437 | return IRQ_HANDLED; |
| 438 | } |
| 439 | |
| 440 | hevt->event_handler(hevt); |
| 441 | return IRQ_HANDLED; |
| 442 | } |
| 443 | |
| 444 | static int hpet_setup_irq(struct hpet_dev *dev) |
| 445 | { |
| 446 | |
| 447 | if (request_irq(dev->irq, hpet_interrupt_handler, |
Matt Fleming | 5ceb1a0 | 2008-11-02 22:23:13 +0000 | [diff] [blame] | 448 | IRQF_DISABLED|IRQF_NOBALANCING, dev->name, dev)) |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 449 | return -1; |
| 450 | |
| 451 | disable_irq(dev->irq); |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame^] | 452 | irq_set_affinity(dev->irq, cpumask_of(dev->cpu)); |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 453 | enable_irq(dev->irq); |
| 454 | |
Yinghai Lu | c81bba4 | 2008-09-25 11:53:11 -0700 | [diff] [blame] | 455 | printk(KERN_DEBUG "hpet: %s irq %d for MSI\n", |
| 456 | dev->name, dev->irq); |
| 457 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | /* This should be called in specific @cpu */ |
| 462 | static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu) |
| 463 | { |
| 464 | struct clock_event_device *evt = &hdev->evt; |
| 465 | uint64_t hpet_freq; |
| 466 | |
| 467 | WARN_ON(cpu != smp_processor_id()); |
| 468 | if (!(hdev->flags & HPET_DEV_VALID)) |
| 469 | return; |
| 470 | |
| 471 | if (hpet_setup_msi_irq(hdev->irq)) |
| 472 | return; |
| 473 | |
| 474 | hdev->cpu = cpu; |
| 475 | per_cpu(cpu_hpet_dev, cpu) = hdev; |
| 476 | evt->name = hdev->name; |
| 477 | hpet_setup_irq(hdev); |
| 478 | evt->irq = hdev->irq; |
| 479 | |
| 480 | evt->rating = 110; |
| 481 | evt->features = CLOCK_EVT_FEAT_ONESHOT; |
| 482 | if (hdev->flags & HPET_DEV_PERI_CAP) |
| 483 | evt->features |= CLOCK_EVT_FEAT_PERIODIC; |
| 484 | |
| 485 | evt->set_mode = hpet_msi_set_mode; |
| 486 | evt->set_next_event = hpet_msi_next_event; |
| 487 | evt->shift = 32; |
| 488 | |
| 489 | /* |
| 490 | * The period is a femto seconds value. We need to calculate the |
| 491 | * scaled math multiplication factor for nanosecond to hpet tick |
| 492 | * conversion. |
| 493 | */ |
| 494 | hpet_freq = 1000000000000000ULL; |
| 495 | do_div(hpet_freq, hpet_period); |
| 496 | evt->mult = div_sc((unsigned long) hpet_freq, |
| 497 | NSEC_PER_SEC, evt->shift); |
| 498 | /* Calculate the max delta */ |
| 499 | evt->max_delta_ns = clockevent_delta2ns(0x7FFFFFFF, evt); |
| 500 | /* 5 usec minimum reprogramming delta. */ |
| 501 | evt->min_delta_ns = 5000; |
| 502 | |
| 503 | evt->cpumask = cpumask_of_cpu(hdev->cpu); |
| 504 | clockevents_register_device(evt); |
| 505 | } |
| 506 | |
| 507 | #ifdef CONFIG_HPET |
| 508 | /* Reserve at least one timer for userspace (/dev/hpet) */ |
| 509 | #define RESERVE_TIMERS 1 |
| 510 | #else |
| 511 | #define RESERVE_TIMERS 0 |
| 512 | #endif |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 513 | |
| 514 | static void hpet_msi_capability_lookup(unsigned int start_timer) |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 515 | { |
| 516 | unsigned int id; |
| 517 | unsigned int num_timers; |
| 518 | unsigned int num_timers_used = 0; |
| 519 | int i; |
| 520 | |
| 521 | id = hpet_readl(HPET_ID); |
| 522 | |
| 523 | num_timers = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT); |
| 524 | num_timers++; /* Value read out starts from 0 */ |
| 525 | |
| 526 | hpet_devs = kzalloc(sizeof(struct hpet_dev) * num_timers, GFP_KERNEL); |
| 527 | if (!hpet_devs) |
| 528 | return; |
| 529 | |
| 530 | hpet_num_timers = num_timers; |
| 531 | |
| 532 | for (i = start_timer; i < num_timers - RESERVE_TIMERS; i++) { |
| 533 | struct hpet_dev *hdev = &hpet_devs[num_timers_used]; |
| 534 | unsigned long cfg = hpet_readl(HPET_Tn_CFG(i)); |
| 535 | |
| 536 | /* Only consider HPET timer with MSI support */ |
| 537 | if (!(cfg & HPET_TN_FSB_CAP)) |
| 538 | continue; |
| 539 | |
| 540 | hdev->flags = 0; |
| 541 | if (cfg & HPET_TN_PERIODIC_CAP) |
| 542 | hdev->flags |= HPET_DEV_PERI_CAP; |
| 543 | hdev->num = i; |
| 544 | |
| 545 | sprintf(hdev->name, "hpet%d", i); |
| 546 | if (hpet_assign_irq(hdev)) |
| 547 | continue; |
| 548 | |
| 549 | hdev->flags |= HPET_DEV_FSB_CAP; |
| 550 | hdev->flags |= HPET_DEV_VALID; |
| 551 | num_timers_used++; |
| 552 | if (num_timers_used == num_possible_cpus()) |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | printk(KERN_INFO "HPET: %d timers in total, %d timers will be used for per-cpu timer\n", |
| 557 | num_timers, num_timers_used); |
| 558 | } |
| 559 | |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 560 | #ifdef CONFIG_HPET |
| 561 | static void hpet_reserve_msi_timers(struct hpet_data *hd) |
| 562 | { |
| 563 | int i; |
| 564 | |
| 565 | if (!hpet_devs) |
| 566 | return; |
| 567 | |
| 568 | for (i = 0; i < hpet_num_timers; i++) { |
| 569 | struct hpet_dev *hdev = &hpet_devs[i]; |
| 570 | |
| 571 | if (!(hdev->flags & HPET_DEV_VALID)) |
| 572 | continue; |
| 573 | |
| 574 | hd->hd_irq[hdev->num] = hdev->irq; |
| 575 | hpet_reserve_timer(hd, hdev->num); |
| 576 | } |
| 577 | } |
| 578 | #endif |
| 579 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 580 | static struct hpet_dev *hpet_get_unused_timer(void) |
| 581 | { |
| 582 | int i; |
| 583 | |
| 584 | if (!hpet_devs) |
| 585 | return NULL; |
| 586 | |
| 587 | for (i = 0; i < hpet_num_timers; i++) { |
| 588 | struct hpet_dev *hdev = &hpet_devs[i]; |
| 589 | |
| 590 | if (!(hdev->flags & HPET_DEV_VALID)) |
| 591 | continue; |
| 592 | if (test_and_set_bit(HPET_DEV_USED_BIT, |
| 593 | (unsigned long *)&hdev->flags)) |
| 594 | continue; |
| 595 | return hdev; |
| 596 | } |
| 597 | return NULL; |
| 598 | } |
| 599 | |
| 600 | struct hpet_work_struct { |
| 601 | struct delayed_work work; |
| 602 | struct completion complete; |
| 603 | }; |
| 604 | |
| 605 | static void hpet_work(struct work_struct *w) |
| 606 | { |
| 607 | struct hpet_dev *hdev; |
| 608 | int cpu = smp_processor_id(); |
| 609 | struct hpet_work_struct *hpet_work; |
| 610 | |
| 611 | hpet_work = container_of(w, struct hpet_work_struct, work.work); |
| 612 | |
| 613 | hdev = hpet_get_unused_timer(); |
| 614 | if (hdev) |
| 615 | init_one_hpet_msi_clockevent(hdev, cpu); |
| 616 | |
| 617 | complete(&hpet_work->complete); |
| 618 | } |
| 619 | |
| 620 | static int hpet_cpuhp_notify(struct notifier_block *n, |
| 621 | unsigned long action, void *hcpu) |
| 622 | { |
| 623 | unsigned long cpu = (unsigned long)hcpu; |
| 624 | struct hpet_work_struct work; |
| 625 | struct hpet_dev *hdev = per_cpu(cpu_hpet_dev, cpu); |
| 626 | |
| 627 | switch (action & 0xf) { |
| 628 | case CPU_ONLINE: |
| 629 | INIT_DELAYED_WORK(&work.work, hpet_work); |
| 630 | init_completion(&work.complete); |
| 631 | /* FIXME: add schedule_work_on() */ |
| 632 | schedule_delayed_work_on(cpu, &work.work, 0); |
| 633 | wait_for_completion(&work.complete); |
| 634 | break; |
| 635 | case CPU_DEAD: |
| 636 | if (hdev) { |
| 637 | free_irq(hdev->irq, hdev); |
| 638 | hdev->flags &= ~HPET_DEV_USED; |
| 639 | per_cpu(cpu_hpet_dev, cpu) = NULL; |
| 640 | } |
| 641 | break; |
| 642 | } |
| 643 | return NOTIFY_OK; |
| 644 | } |
| 645 | #else |
| 646 | |
Steven Noonan | ba374c9 | 2008-09-08 16:19:09 -0700 | [diff] [blame] | 647 | static int hpet_setup_msi_irq(unsigned int irq) |
| 648 | { |
| 649 | return 0; |
| 650 | } |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 651 | static void hpet_msi_capability_lookup(unsigned int start_timer) |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 652 | { |
| 653 | return; |
| 654 | } |
| 655 | |
Venki Pallipadi | 5f79f2f | 2008-09-24 10:03:17 -0700 | [diff] [blame] | 656 | #ifdef CONFIG_HPET |
| 657 | static void hpet_reserve_msi_timers(struct hpet_data *hd) |
| 658 | { |
| 659 | return; |
| 660 | } |
| 661 | #endif |
| 662 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 663 | static int hpet_cpuhp_notify(struct notifier_block *n, |
| 664 | unsigned long action, void *hcpu) |
| 665 | { |
| 666 | return NOTIFY_OK; |
| 667 | } |
| 668 | |
| 669 | #endif |
| 670 | |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 671 | /* |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 672 | * Clock source related code |
| 673 | */ |
| 674 | static cycle_t read_hpet(void) |
| 675 | { |
| 676 | return (cycle_t)hpet_readl(HPET_COUNTER); |
| 677 | } |
| 678 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 679 | #ifdef CONFIG_X86_64 |
| 680 | static cycle_t __vsyscall_fn vread_hpet(void) |
| 681 | { |
| 682 | return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0); |
| 683 | } |
| 684 | #endif |
| 685 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 686 | static struct clocksource clocksource_hpet = { |
| 687 | .name = "hpet", |
| 688 | .rating = 250, |
| 689 | .read = read_hpet, |
| 690 | .mask = HPET_MASK, |
| 691 | .shift = HPET_SHIFT, |
| 692 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 693 | .resume = hpet_restart_counter, |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 694 | #ifdef CONFIG_X86_64 |
| 695 | .vread = vread_hpet, |
| 696 | #endif |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 697 | }; |
| 698 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 699 | static int hpet_clocksource_register(void) |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 700 | { |
Carlos R. Mafra | 6fd592d | 2008-05-05 20:11:22 -0300 | [diff] [blame] | 701 | u64 start, now; |
Thomas Gleixner | 075bcd1 | 2007-07-21 17:11:12 +0200 | [diff] [blame] | 702 | cycle_t t1; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 703 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 704 | /* Start the counter */ |
| 705 | hpet_start_counter(); |
| 706 | |
Thomas Gleixner | 075bcd1 | 2007-07-21 17:11:12 +0200 | [diff] [blame] | 707 | /* Verify whether hpet counter works */ |
| 708 | t1 = read_hpet(); |
| 709 | rdtscll(start); |
| 710 | |
| 711 | /* |
| 712 | * We don't know the TSC frequency yet, but waiting for |
| 713 | * 200000 TSC cycles is safe: |
| 714 | * 4 GHz == 50us |
| 715 | * 1 GHz == 200us |
| 716 | */ |
| 717 | do { |
| 718 | rep_nop(); |
| 719 | rdtscll(now); |
| 720 | } while ((now - start) < 200000UL); |
| 721 | |
| 722 | if (t1 == read_hpet()) { |
| 723 | printk(KERN_WARNING |
| 724 | "HPET counter not counting. HPET disabled\n"); |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 725 | return -ENODEV; |
Thomas Gleixner | 075bcd1 | 2007-07-21 17:11:12 +0200 | [diff] [blame] | 726 | } |
| 727 | |
Carlos R. Mafra | 6fd592d | 2008-05-05 20:11:22 -0300 | [diff] [blame] | 728 | /* |
| 729 | * The definition of mult is (include/linux/clocksource.h) |
| 730 | * mult/2^shift = ns/cyc and hpet_period is in units of fsec/cyc |
| 731 | * so we first need to convert hpet_period to ns/cyc units: |
| 732 | * mult/2^shift = ns/cyc = hpet_period/10^6 |
| 733 | * mult = (hpet_period * 2^shift)/10^6 |
| 734 | * mult = (hpet_period << shift)/FSEC_PER_NSEC |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 735 | */ |
Carlos R. Mafra | 6fd592d | 2008-05-05 20:11:22 -0300 | [diff] [blame] | 736 | clocksource_hpet.mult = div_sc(hpet_period, FSEC_PER_NSEC, HPET_SHIFT); |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 737 | |
| 738 | clocksource_register(&clocksource_hpet); |
| 739 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 740 | return 0; |
| 741 | } |
| 742 | |
Pavel Machek | b02a7f2 | 2008-02-05 00:48:13 +0100 | [diff] [blame] | 743 | /** |
| 744 | * hpet_enable - Try to setup the HPET timer. Returns 1 on success. |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 745 | */ |
| 746 | int __init hpet_enable(void) |
| 747 | { |
| 748 | unsigned long id; |
Thomas Gleixner | a6825f1 | 2008-08-14 12:17:06 +0200 | [diff] [blame] | 749 | int i; |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 750 | |
| 751 | if (!is_hpet_capable()) |
| 752 | return 0; |
| 753 | |
| 754 | hpet_set_mapping(); |
| 755 | |
| 756 | /* |
| 757 | * Read the period and check for a sane value: |
| 758 | */ |
| 759 | hpet_period = hpet_readl(HPET_PERIOD); |
Thomas Gleixner | a6825f1 | 2008-08-14 12:17:06 +0200 | [diff] [blame] | 760 | |
| 761 | /* |
| 762 | * AMD SB700 based systems with spread spectrum enabled use a |
| 763 | * SMM based HPET emulation to provide proper frequency |
| 764 | * setting. The SMM code is initialized with the first HPET |
| 765 | * register access and takes some time to complete. During |
| 766 | * this time the config register reads 0xffffffff. We check |
| 767 | * for max. 1000 loops whether the config register reads a non |
| 768 | * 0xffffffff value to make sure that HPET is up and running |
| 769 | * before we go further. A counting loop is safe, as the HPET |
| 770 | * access takes thousands of CPU cycles. On non SB700 based |
| 771 | * machines this check is only done once and has no side |
| 772 | * effects. |
| 773 | */ |
| 774 | for (i = 0; hpet_readl(HPET_CFG) == 0xFFFFFFFF; i++) { |
| 775 | if (i == 1000) { |
| 776 | printk(KERN_WARNING |
| 777 | "HPET config register value = 0xFFFFFFFF. " |
| 778 | "Disabling HPET\n"); |
| 779 | goto out_nohpet; |
| 780 | } |
| 781 | } |
| 782 | |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 783 | if (hpet_period < HPET_MIN_PERIOD || hpet_period > HPET_MAX_PERIOD) |
| 784 | goto out_nohpet; |
| 785 | |
| 786 | /* |
| 787 | * Read the HPET ID register to retrieve the IRQ routing |
| 788 | * information and the number of channels |
| 789 | */ |
| 790 | id = hpet_readl(HPET_ID); |
| 791 | |
| 792 | #ifdef CONFIG_HPET_EMULATE_RTC |
| 793 | /* |
| 794 | * The legacy routing mode needs at least two channels, tick timer |
| 795 | * and the rtc emulation channel. |
| 796 | */ |
| 797 | if (!(id & HPET_ID_NUMBER)) |
| 798 | goto out_nohpet; |
| 799 | #endif |
| 800 | |
| 801 | if (hpet_clocksource_register()) |
| 802 | goto out_nohpet; |
| 803 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 804 | if (id & HPET_ID_LEGSUP) { |
Venki Pallipadi | 610bf2f | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 805 | hpet_legacy_clockevent_register(); |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 806 | hpet_msi_capability_lookup(2); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 807 | return 1; |
| 808 | } |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 809 | hpet_msi_capability_lookup(0); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 810 | return 0; |
| 811 | |
| 812 | out_nohpet: |
Thomas Gleixner | 06a24de | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 813 | hpet_clear_mapping(); |
Maxim Levitsky | 399afa4 | 2007-03-29 15:46:48 +0200 | [diff] [blame] | 814 | boot_hpet_disable = 1; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 818 | /* |
| 819 | * Needs to be late, as the reserve_timer code calls kalloc ! |
| 820 | * |
| 821 | * Not a problem on i386 as hpet_enable is called from late_time_init, |
| 822 | * but on x86_64 it is necessary ! |
| 823 | */ |
| 824 | static __init int hpet_late_init(void) |
| 825 | { |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 826 | int cpu; |
| 827 | |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 828 | if (boot_hpet_disable) |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 829 | return -ENODEV; |
| 830 | |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 831 | if (!hpet_address) { |
| 832 | if (!force_hpet_address) |
| 833 | return -ENODEV; |
| 834 | |
| 835 | hpet_address = force_hpet_address; |
| 836 | hpet_enable(); |
| 837 | if (!hpet_virt_address) |
| 838 | return -ENODEV; |
| 839 | } |
| 840 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 841 | hpet_reserve_platform_timers(hpet_readl(HPET_ID)); |
Venki Pallipadi | 59c69f2 | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 842 | |
venkatesh.pallipadi@intel.com | 26afe5f | 2008-09-05 18:02:18 -0700 | [diff] [blame] | 843 | for_each_online_cpu(cpu) { |
| 844 | hpet_cpuhp_notify(NULL, CPU_ONLINE, (void *)(long)cpu); |
| 845 | } |
| 846 | |
| 847 | /* This notifier should be called after workqueue is ready */ |
| 848 | hotcpu_notifier(hpet_cpuhp_notify, -20); |
| 849 | |
Thomas Gleixner | 2876914 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | fs_initcall(hpet_late_init); |
| 853 | |
OGAWA Hirofumi | c86c7fb | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 854 | void hpet_disable(void) |
| 855 | { |
| 856 | if (is_hpet_capable()) { |
| 857 | unsigned long cfg = hpet_readl(HPET_CFG); |
| 858 | |
| 859 | if (hpet_legacy_int_enabled) { |
| 860 | cfg &= ~HPET_CFG_LEGACY; |
| 861 | hpet_legacy_int_enabled = 0; |
| 862 | } |
| 863 | cfg &= ~HPET_CFG_ENABLE; |
| 864 | hpet_writel(cfg, HPET_CFG); |
| 865 | } |
| 866 | } |
| 867 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 868 | #ifdef CONFIG_HPET_EMULATE_RTC |
| 869 | |
| 870 | /* HPET in LegacyReplacement Mode eats up RTC interrupt line. When, HPET |
| 871 | * is enabled, we support RTC interrupt functionality in software. |
| 872 | * RTC has 3 kinds of interrupts: |
| 873 | * 1) Update Interrupt - generate an interrupt, every sec, when RTC clock |
| 874 | * is updated |
| 875 | * 2) Alarm Interrupt - generate an interrupt at a specific time of day |
| 876 | * 3) Periodic Interrupt - generate periodic interrupt, with frequencies |
| 877 | * 2Hz-8192Hz (2Hz-64Hz for non-root user) (all freqs in powers of 2) |
| 878 | * (1) and (2) above are implemented using polling at a frequency of |
| 879 | * 64 Hz. The exact frequency is a tradeoff between accuracy and interrupt |
| 880 | * overhead. (DEFAULT_RTC_INT_FREQ) |
| 881 | * For (3), we use interrupts at 64Hz or user specified periodic |
| 882 | * frequency, whichever is higher. |
| 883 | */ |
| 884 | #include <linux/mc146818rtc.h> |
| 885 | #include <linux/rtc.h> |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 886 | #include <asm/rtc.h> |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 887 | |
| 888 | #define DEFAULT_RTC_INT_FREQ 64 |
| 889 | #define DEFAULT_RTC_SHIFT 6 |
| 890 | #define RTC_NUM_INTS 1 |
| 891 | |
| 892 | static unsigned long hpet_rtc_flags; |
David Brownell | 7e2a31d | 2008-07-23 21:30:47 -0700 | [diff] [blame] | 893 | static int hpet_prev_update_sec; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 894 | static struct rtc_time hpet_alarm_time; |
| 895 | static unsigned long hpet_pie_count; |
| 896 | static unsigned long hpet_t1_cmp; |
| 897 | static unsigned long hpet_default_delta; |
| 898 | static unsigned long hpet_pie_delta; |
| 899 | static unsigned long hpet_pie_limit; |
| 900 | |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 901 | static rtc_irq_handler irq_handler; |
| 902 | |
| 903 | /* |
| 904 | * Registers a IRQ handler. |
| 905 | */ |
| 906 | int hpet_register_irq_handler(rtc_irq_handler handler) |
| 907 | { |
| 908 | if (!is_hpet_enabled()) |
| 909 | return -ENODEV; |
| 910 | if (irq_handler) |
| 911 | return -EBUSY; |
| 912 | |
| 913 | irq_handler = handler; |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | EXPORT_SYMBOL_GPL(hpet_register_irq_handler); |
| 918 | |
| 919 | /* |
| 920 | * Deregisters the IRQ handler registered with hpet_register_irq_handler() |
| 921 | * and does cleanup. |
| 922 | */ |
| 923 | void hpet_unregister_irq_handler(rtc_irq_handler handler) |
| 924 | { |
| 925 | if (!is_hpet_enabled()) |
| 926 | return; |
| 927 | |
| 928 | irq_handler = NULL; |
| 929 | hpet_rtc_flags = 0; |
| 930 | } |
| 931 | EXPORT_SYMBOL_GPL(hpet_unregister_irq_handler); |
| 932 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 933 | /* |
| 934 | * Timer 1 for RTC emulation. We use one shot mode, as periodic mode |
| 935 | * is not supported by all HPET implementations for timer 1. |
| 936 | * |
| 937 | * hpet_rtc_timer_init() is called when the rtc is initialized. |
| 938 | */ |
| 939 | int hpet_rtc_timer_init(void) |
| 940 | { |
| 941 | unsigned long cfg, cnt, delta, flags; |
| 942 | |
| 943 | if (!is_hpet_enabled()) |
| 944 | return 0; |
| 945 | |
| 946 | if (!hpet_default_delta) { |
| 947 | uint64_t clc; |
| 948 | |
| 949 | clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC; |
| 950 | clc >>= hpet_clockevent.shift + DEFAULT_RTC_SHIFT; |
| 951 | hpet_default_delta = (unsigned long) clc; |
| 952 | } |
| 953 | |
| 954 | if (!(hpet_rtc_flags & RTC_PIE) || hpet_pie_limit) |
| 955 | delta = hpet_default_delta; |
| 956 | else |
| 957 | delta = hpet_pie_delta; |
| 958 | |
| 959 | local_irq_save(flags); |
| 960 | |
| 961 | cnt = delta + hpet_readl(HPET_COUNTER); |
| 962 | hpet_writel(cnt, HPET_T1_CMP); |
| 963 | hpet_t1_cmp = cnt; |
| 964 | |
| 965 | cfg = hpet_readl(HPET_T1_CFG); |
| 966 | cfg &= ~HPET_TN_PERIODIC; |
| 967 | cfg |= HPET_TN_ENABLE | HPET_TN_32BIT; |
| 968 | hpet_writel(cfg, HPET_T1_CFG); |
| 969 | |
| 970 | local_irq_restore(flags); |
| 971 | |
| 972 | return 1; |
| 973 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 974 | EXPORT_SYMBOL_GPL(hpet_rtc_timer_init); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 975 | |
| 976 | /* |
| 977 | * The functions below are called from rtc driver. |
| 978 | * Return 0 if HPET is not being used. |
| 979 | * Otherwise do the necessary changes and return 1. |
| 980 | */ |
| 981 | int hpet_mask_rtc_irq_bit(unsigned long bit_mask) |
| 982 | { |
| 983 | if (!is_hpet_enabled()) |
| 984 | return 0; |
| 985 | |
| 986 | hpet_rtc_flags &= ~bit_mask; |
| 987 | return 1; |
| 988 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 989 | EXPORT_SYMBOL_GPL(hpet_mask_rtc_irq_bit); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 990 | |
| 991 | int hpet_set_rtc_irq_bit(unsigned long bit_mask) |
| 992 | { |
| 993 | unsigned long oldbits = hpet_rtc_flags; |
| 994 | |
| 995 | if (!is_hpet_enabled()) |
| 996 | return 0; |
| 997 | |
| 998 | hpet_rtc_flags |= bit_mask; |
| 999 | |
David Brownell | 7e2a31d | 2008-07-23 21:30:47 -0700 | [diff] [blame] | 1000 | if ((bit_mask & RTC_UIE) && !(oldbits & RTC_UIE)) |
| 1001 | hpet_prev_update_sec = -1; |
| 1002 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1003 | if (!oldbits) |
| 1004 | hpet_rtc_timer_init(); |
| 1005 | |
| 1006 | return 1; |
| 1007 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1008 | EXPORT_SYMBOL_GPL(hpet_set_rtc_irq_bit); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1009 | |
| 1010 | int hpet_set_alarm_time(unsigned char hrs, unsigned char min, |
| 1011 | unsigned char sec) |
| 1012 | { |
| 1013 | if (!is_hpet_enabled()) |
| 1014 | return 0; |
| 1015 | |
| 1016 | hpet_alarm_time.tm_hour = hrs; |
| 1017 | hpet_alarm_time.tm_min = min; |
| 1018 | hpet_alarm_time.tm_sec = sec; |
| 1019 | |
| 1020 | return 1; |
| 1021 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1022 | EXPORT_SYMBOL_GPL(hpet_set_alarm_time); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1023 | |
| 1024 | int hpet_set_periodic_freq(unsigned long freq) |
| 1025 | { |
| 1026 | uint64_t clc; |
| 1027 | |
| 1028 | if (!is_hpet_enabled()) |
| 1029 | return 0; |
| 1030 | |
| 1031 | if (freq <= DEFAULT_RTC_INT_FREQ) |
| 1032 | hpet_pie_limit = DEFAULT_RTC_INT_FREQ / freq; |
| 1033 | else { |
| 1034 | clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC; |
| 1035 | do_div(clc, freq); |
| 1036 | clc >>= hpet_clockevent.shift; |
| 1037 | hpet_pie_delta = (unsigned long) clc; |
| 1038 | } |
| 1039 | return 1; |
| 1040 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1041 | EXPORT_SYMBOL_GPL(hpet_set_periodic_freq); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1042 | |
| 1043 | int hpet_rtc_dropped_irq(void) |
| 1044 | { |
| 1045 | return is_hpet_enabled(); |
| 1046 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1047 | EXPORT_SYMBOL_GPL(hpet_rtc_dropped_irq); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1048 | |
| 1049 | static void hpet_rtc_timer_reinit(void) |
| 1050 | { |
| 1051 | unsigned long cfg, delta; |
| 1052 | int lost_ints = -1; |
| 1053 | |
| 1054 | if (unlikely(!hpet_rtc_flags)) { |
| 1055 | cfg = hpet_readl(HPET_T1_CFG); |
| 1056 | cfg &= ~HPET_TN_ENABLE; |
| 1057 | hpet_writel(cfg, HPET_T1_CFG); |
| 1058 | return; |
| 1059 | } |
| 1060 | |
| 1061 | if (!(hpet_rtc_flags & RTC_PIE) || hpet_pie_limit) |
| 1062 | delta = hpet_default_delta; |
| 1063 | else |
| 1064 | delta = hpet_pie_delta; |
| 1065 | |
| 1066 | /* |
| 1067 | * Increment the comparator value until we are ahead of the |
| 1068 | * current count. |
| 1069 | */ |
| 1070 | do { |
| 1071 | hpet_t1_cmp += delta; |
| 1072 | hpet_writel(hpet_t1_cmp, HPET_T1_CMP); |
| 1073 | lost_ints++; |
| 1074 | } while ((long)(hpet_readl(HPET_COUNTER) - hpet_t1_cmp) > 0); |
| 1075 | |
| 1076 | if (lost_ints) { |
| 1077 | if (hpet_rtc_flags & RTC_PIE) |
| 1078 | hpet_pie_count += lost_ints; |
| 1079 | if (printk_ratelimit()) |
David Brownell | 7e2a31d | 2008-07-23 21:30:47 -0700 | [diff] [blame] | 1080 | printk(KERN_WARNING "hpet1: lost %d rtc interrupts\n", |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1081 | lost_ints); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) |
| 1086 | { |
| 1087 | struct rtc_time curr_time; |
| 1088 | unsigned long rtc_int_flag = 0; |
| 1089 | |
| 1090 | hpet_rtc_timer_reinit(); |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1091 | memset(&curr_time, 0, sizeof(struct rtc_time)); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1092 | |
| 1093 | if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1094 | get_rtc_time(&curr_time); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1095 | |
| 1096 | if (hpet_rtc_flags & RTC_UIE && |
| 1097 | curr_time.tm_sec != hpet_prev_update_sec) { |
David Brownell | 7e2a31d | 2008-07-23 21:30:47 -0700 | [diff] [blame] | 1098 | if (hpet_prev_update_sec >= 0) |
| 1099 | rtc_int_flag = RTC_UF; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1100 | hpet_prev_update_sec = curr_time.tm_sec; |
| 1101 | } |
| 1102 | |
| 1103 | if (hpet_rtc_flags & RTC_PIE && |
| 1104 | ++hpet_pie_count >= hpet_pie_limit) { |
| 1105 | rtc_int_flag |= RTC_PF; |
| 1106 | hpet_pie_count = 0; |
| 1107 | } |
| 1108 | |
Bernhard Walle | 8ee291f | 2008-01-15 16:44:38 +0100 | [diff] [blame] | 1109 | if (hpet_rtc_flags & RTC_AIE && |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1110 | (curr_time.tm_sec == hpet_alarm_time.tm_sec) && |
| 1111 | (curr_time.tm_min == hpet_alarm_time.tm_min) && |
| 1112 | (curr_time.tm_hour == hpet_alarm_time.tm_hour)) |
| 1113 | rtc_int_flag |= RTC_AF; |
| 1114 | |
| 1115 | if (rtc_int_flag) { |
| 1116 | rtc_int_flag |= (RTC_IRQF | (RTC_NUM_INTS << 8)); |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1117 | if (irq_handler) |
| 1118 | irq_handler(rtc_int_flag, dev_id); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1119 | } |
| 1120 | return IRQ_HANDLED; |
| 1121 | } |
Bernhard Walle | 1bdbdaa | 2008-01-30 13:33:28 +0100 | [diff] [blame] | 1122 | EXPORT_SYMBOL_GPL(hpet_rtc_interrupt); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1123 | #endif |