2 * Intel & MS High Precision Event Timer Implementation.
4 * Copyright (C) 2003 Intel Corporation
6 * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
7 * Bob Picco <robert.picco@hp.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/miscdevice.h>
19 #include <linux/major.h>
20 #include <linux/ioport.h>
21 #include <linux/fcntl.h>
22 #include <linux/init.h>
23 #include <linux/poll.h>
25 #include <linux/proc_fs.h>
26 #include <linux/spinlock.h>
27 #include <linux/sysctl.h>
28 #include <linux/wait.h>
29 #include <linux/bcd.h>
30 #include <linux/seq_file.h>
31 #include <linux/bitops.h>
32 #include <linux/clocksource.h>
34 #include <asm/current.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
39 #include <asm/div64.h>
41 #include <linux/acpi.h>
42 #include <acpi/acpi_bus.h>
43 #include <linux/hpet.h>
46 * The High Precision Event Timer driver.
47 * This driver is closely modelled after the rtc.c driver.
48 * http://www.intel.com/hardwaredesign/hpetspec.htm
50 #define HPET_USER_FREQ (64)
51 #define HPET_DRIFT (500)
53 #define HPET_RANGE_SIZE 1024 /* from HPET spec */
55 #if BITS_PER_LONG == 64
56 #define write_counter(V, MC) writeq(V, MC)
57 #define read_counter(MC) readq(MC)
59 #define write_counter(V, MC) writel(V, MC)
60 #define read_counter(MC) readl(MC)
63 static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
65 static void __iomem *hpet_mctr;
67 static cycle_t read_hpet(void)
69 return (cycle_t)read_counter((void __iomem *)hpet_mctr);
72 static struct clocksource clocksource_hpet = {
76 .mask = CLOCKSOURCE_MASK(64),
77 .mult = 0, /*to be caluclated*/
79 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
81 static struct clocksource *hpet_clocksource;
83 /* A lock for concurrent access by app and isr hpet activity. */
84 static DEFINE_SPINLOCK(hpet_lock);
85 /* A lock for concurrent intermodule access to hpet and isr hpet activity. */
86 static DEFINE_SPINLOCK(hpet_task_lock);
88 #define HPET_DEV_NAME (7)
91 struct hpets *hd_hpets;
92 struct hpet __iomem *hd_hpet;
93 struct hpet_timer __iomem *hd_timer;
94 unsigned long hd_ireqfreq;
95 unsigned long hd_irqdata;
96 wait_queue_head_t hd_waitqueue;
97 struct fasync_struct *hd_async_queue;
98 struct hpet_task *hd_task;
99 unsigned int hd_flags;
101 unsigned int hd_hdwirq;
102 char hd_name[HPET_DEV_NAME];
106 struct hpets *hp_next;
107 struct hpet __iomem *hp_hpet;
108 unsigned long hp_hpet_phys;
109 struct clocksource *hp_clocksource;
110 unsigned long long hp_tick_freq;
111 unsigned long hp_delta;
112 unsigned int hp_ntimer;
113 unsigned int hp_which;
114 struct hpet_dev hp_dev[1];
117 static struct hpets *hpets;
119 #define HPET_OPEN 0x0001
120 #define HPET_IE 0x0002 /* interrupt enabled */
121 #define HPET_PERIODIC 0x0004
122 #define HPET_SHARED_IRQ 0x0008
126 static inline unsigned long long readq(void __iomem *addr)
128 return readl(addr) | (((unsigned long long)readl(addr + 4)) << 32LL);
133 static inline void writeq(unsigned long long v, void __iomem *addr)
135 writel(v & 0xffffffff, addr);
136 writel(v >> 32, addr + 4);
140 static irqreturn_t hpet_interrupt(int irq, void *data)
142 struct hpet_dev *devp;
146 isr = 1 << (devp - devp->hd_hpets->hp_dev);
148 if ((devp->hd_flags & HPET_SHARED_IRQ) &&
149 !(isr & readl(&devp->hd_hpet->hpet_isr)))
152 spin_lock(&hpet_lock);
156 * For non-periodic timers, increment the accumulator.
157 * This has the effect of treating non-periodic like periodic.
159 if ((devp->hd_flags & (HPET_IE | HPET_PERIODIC)) == HPET_IE) {
162 t = devp->hd_ireqfreq;
163 m = read_counter(&devp->hd_hpet->hpet_mc);
164 write_counter(t + m + devp->hd_hpets->hp_delta,
165 &devp->hd_timer->hpet_compare);
168 if (devp->hd_flags & HPET_SHARED_IRQ)
169 writel(isr, &devp->hd_hpet->hpet_isr);
170 spin_unlock(&hpet_lock);
172 spin_lock(&hpet_task_lock);
174 devp->hd_task->ht_func(devp->hd_task->ht_data);
175 spin_unlock(&hpet_task_lock);
177 wake_up_interruptible(&devp->hd_waitqueue);
179 kill_fasync(&devp->hd_async_queue, SIGIO, POLL_IN);
184 static int hpet_open(struct inode *inode, struct file *file)
186 struct hpet_dev *devp;
190 if (file->f_mode & FMODE_WRITE)
193 spin_lock_irq(&hpet_lock);
195 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
196 for (i = 0; i < hpetp->hp_ntimer; i++)
197 if (hpetp->hp_dev[i].hd_flags & HPET_OPEN
198 || hpetp->hp_dev[i].hd_task)
201 devp = &hpetp->hp_dev[i];
206 spin_unlock_irq(&hpet_lock);
210 file->private_data = devp;
211 devp->hd_irqdata = 0;
212 devp->hd_flags |= HPET_OPEN;
213 spin_unlock_irq(&hpet_lock);
219 hpet_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
221 DECLARE_WAITQUEUE(wait, current);
224 struct hpet_dev *devp;
226 devp = file->private_data;
227 if (!devp->hd_ireqfreq)
230 if (count < sizeof(unsigned long))
233 add_wait_queue(&devp->hd_waitqueue, &wait);
236 set_current_state(TASK_INTERRUPTIBLE);
238 spin_lock_irq(&hpet_lock);
239 data = devp->hd_irqdata;
240 devp->hd_irqdata = 0;
241 spin_unlock_irq(&hpet_lock);
245 else if (file->f_flags & O_NONBLOCK) {
248 } else if (signal_pending(current)) {
249 retval = -ERESTARTSYS;
255 retval = put_user(data, (unsigned long __user *)buf);
257 retval = sizeof(unsigned long);
259 __set_current_state(TASK_RUNNING);
260 remove_wait_queue(&devp->hd_waitqueue, &wait);
265 static unsigned int hpet_poll(struct file *file, poll_table * wait)
268 struct hpet_dev *devp;
270 devp = file->private_data;
272 if (!devp->hd_ireqfreq)
275 poll_wait(file, &devp->hd_waitqueue, wait);
277 spin_lock_irq(&hpet_lock);
278 v = devp->hd_irqdata;
279 spin_unlock_irq(&hpet_lock);
282 return POLLIN | POLLRDNORM;
287 static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
289 #ifdef CONFIG_HPET_MMAP
290 struct hpet_dev *devp;
293 if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
296 devp = file->private_data;
297 addr = devp->hd_hpets->hp_hpet_phys;
299 if (addr & (PAGE_SIZE - 1))
302 vma->vm_flags |= VM_IO;
303 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
305 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
306 PAGE_SIZE, vma->vm_page_prot)) {
307 printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
318 static int hpet_fasync(int fd, struct file *file, int on)
320 struct hpet_dev *devp;
322 devp = file->private_data;
324 if (fasync_helper(fd, file, on, &devp->hd_async_queue) >= 0)
330 static int hpet_release(struct inode *inode, struct file *file)
332 struct hpet_dev *devp;
333 struct hpet_timer __iomem *timer;
336 devp = file->private_data;
337 timer = devp->hd_timer;
339 spin_lock_irq(&hpet_lock);
341 writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK),
342 &timer->hpet_config);
347 devp->hd_ireqfreq = 0;
349 if (devp->hd_flags & HPET_PERIODIC
350 && readq(&timer->hpet_config) & Tn_TYPE_CNF_MASK) {
353 v = readq(&timer->hpet_config);
354 v ^= Tn_TYPE_CNF_MASK;
355 writeq(v, &timer->hpet_config);
358 devp->hd_flags &= ~(HPET_OPEN | HPET_IE | HPET_PERIODIC);
359 spin_unlock_irq(&hpet_lock);
364 if (file->f_flags & FASYNC)
365 hpet_fasync(-1, file, 0);
367 file->private_data = NULL;
371 static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
374 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
377 struct hpet_dev *devp;
379 devp = file->private_data;
380 return hpet_ioctl_common(devp, cmd, arg, 0);
383 static int hpet_ioctl_ieon(struct hpet_dev *devp)
385 struct hpet_timer __iomem *timer;
386 struct hpet __iomem *hpet;
389 unsigned long g, v, t, m;
390 unsigned long flags, isr;
392 timer = devp->hd_timer;
393 hpet = devp->hd_hpet;
394 hpetp = devp->hd_hpets;
396 if (!devp->hd_ireqfreq)
399 spin_lock_irq(&hpet_lock);
401 if (devp->hd_flags & HPET_IE) {
402 spin_unlock_irq(&hpet_lock);
406 devp->hd_flags |= HPET_IE;
408 if (readl(&timer->hpet_config) & Tn_INT_TYPE_CNF_MASK)
409 devp->hd_flags |= HPET_SHARED_IRQ;
410 spin_unlock_irq(&hpet_lock);
412 irq = devp->hd_hdwirq;
415 unsigned long irq_flags;
417 sprintf(devp->hd_name, "hpet%d", (int)(devp - hpetp->hp_dev));
418 irq_flags = devp->hd_flags & HPET_SHARED_IRQ
419 ? IRQF_SHARED : IRQF_DISABLED;
420 if (request_irq(irq, hpet_interrupt, irq_flags,
421 devp->hd_name, (void *)devp)) {
422 printk(KERN_ERR "hpet: IRQ %d is not free\n", irq);
428 spin_lock_irq(&hpet_lock);
429 devp->hd_flags ^= HPET_IE;
430 spin_unlock_irq(&hpet_lock);
435 t = devp->hd_ireqfreq;
436 v = readq(&timer->hpet_config);
437 g = v | Tn_INT_ENB_CNF_MASK;
439 if (devp->hd_flags & HPET_PERIODIC) {
440 write_counter(t, &timer->hpet_compare);
441 g |= Tn_TYPE_CNF_MASK;
442 v |= Tn_TYPE_CNF_MASK;
443 writeq(v, &timer->hpet_config);
444 v |= Tn_VAL_SET_CNF_MASK;
445 writeq(v, &timer->hpet_config);
446 local_irq_save(flags);
447 m = read_counter(&hpet->hpet_mc);
448 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
450 local_irq_save(flags);
451 m = read_counter(&hpet->hpet_mc);
452 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
455 if (devp->hd_flags & HPET_SHARED_IRQ) {
456 isr = 1 << (devp - devp->hd_hpets->hp_dev);
457 writel(isr, &hpet->hpet_isr);
459 writeq(g, &timer->hpet_config);
460 local_irq_restore(flags);
465 /* converts Hz to number of timer ticks */
466 static inline unsigned long hpet_time_div(struct hpets *hpets,
469 unsigned long long m;
471 m = hpets->hp_tick_freq + (dis >> 1);
473 return (unsigned long)m;
477 hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
479 struct hpet_timer __iomem *timer;
480 struct hpet __iomem *hpet;
491 timer = devp->hd_timer;
492 hpet = devp->hd_hpet;
493 hpetp = devp->hd_hpets;
496 return hpet_ioctl_ieon(devp);
505 if ((devp->hd_flags & HPET_IE) == 0)
507 v = readq(&timer->hpet_config);
508 v &= ~Tn_INT_ENB_CNF_MASK;
509 writeq(v, &timer->hpet_config);
511 free_irq(devp->hd_irq, devp);
514 devp->hd_flags ^= HPET_IE;
518 struct hpet_info info;
520 if (devp->hd_ireqfreq)
522 hpet_time_div(hpetp, devp->hd_ireqfreq);
524 info.hi_ireqfreq = 0;
526 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
527 info.hi_hpet = hpetp->hp_which;
528 info.hi_timer = devp - hpetp->hp_dev;
530 memcpy((void *)arg, &info, sizeof(info));
532 if (copy_to_user((void __user *)arg, &info,
538 v = readq(&timer->hpet_config);
539 if ((v & Tn_PER_INT_CAP_MASK) == 0) {
543 devp->hd_flags |= HPET_PERIODIC;
546 v = readq(&timer->hpet_config);
547 if ((v & Tn_PER_INT_CAP_MASK) == 0) {
551 if (devp->hd_flags & HPET_PERIODIC &&
552 readq(&timer->hpet_config) & Tn_TYPE_CNF_MASK) {
553 v = readq(&timer->hpet_config);
554 v ^= Tn_TYPE_CNF_MASK;
555 writeq(v, &timer->hpet_config);
557 devp->hd_flags &= ~HPET_PERIODIC;
560 if (!kernel && (arg > hpet_max_freq) &&
561 !capable(CAP_SYS_RESOURCE)) {
571 devp->hd_ireqfreq = hpet_time_div(hpetp, arg);
577 static const struct file_operations hpet_fops = {
578 .owner = THIS_MODULE,
584 .release = hpet_release,
585 .fasync = hpet_fasync,
589 static int hpet_is_known(struct hpet_data *hdp)
593 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
594 if (hpetp->hp_hpet_phys == hdp->hd_phys_address)
600 EXPORT_SYMBOL(hpet_alloc);
601 EXPORT_SYMBOL(hpet_register);
602 EXPORT_SYMBOL(hpet_unregister);
603 EXPORT_SYMBOL(hpet_control);
605 int hpet_register(struct hpet_task *tp, int periodic)
609 struct hpet_timer __iomem *timer;
610 struct hpet_dev *devp;
615 mask = Tn_PER_INT_CAP_MASK;
624 tp->ht_opaque = NULL;
626 spin_lock_irq(&hpet_task_lock);
627 spin_lock(&hpet_lock);
629 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
630 for (timer = hpetp->hp_hpet->hpet_timers, i = 0;
631 i < hpetp->hp_ntimer; i++, timer++) {
632 if ((readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK)
636 devp = &hpetp->hp_dev[i];
638 if (devp->hd_flags & HPET_OPEN || devp->hd_task) {
643 tp->ht_opaque = devp;
648 spin_unlock(&hpet_lock);
649 spin_unlock_irq(&hpet_task_lock);
657 static inline int hpet_tpcheck(struct hpet_task *tp)
659 struct hpet_dev *devp;
662 devp = tp->ht_opaque;
667 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
668 if (devp >= hpetp->hp_dev
669 && devp < (hpetp->hp_dev + hpetp->hp_ntimer)
670 && devp->hd_hpet == hpetp->hp_hpet)
676 int hpet_unregister(struct hpet_task *tp)
678 struct hpet_dev *devp;
679 struct hpet_timer __iomem *timer;
682 if ((err = hpet_tpcheck(tp)))
685 spin_lock_irq(&hpet_task_lock);
686 spin_lock(&hpet_lock);
688 devp = tp->ht_opaque;
689 if (devp->hd_task != tp) {
690 spin_unlock(&hpet_lock);
691 spin_unlock_irq(&hpet_task_lock);
695 timer = devp->hd_timer;
696 writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK),
697 &timer->hpet_config);
698 devp->hd_flags &= ~(HPET_IE | HPET_PERIODIC);
699 devp->hd_task = NULL;
700 spin_unlock(&hpet_lock);
701 spin_unlock_irq(&hpet_task_lock);
706 int hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg)
708 struct hpet_dev *devp;
711 if ((err = hpet_tpcheck(tp)))
714 spin_lock_irq(&hpet_lock);
715 devp = tp->ht_opaque;
716 if (devp->hd_task != tp) {
717 spin_unlock_irq(&hpet_lock);
720 spin_unlock_irq(&hpet_lock);
721 return hpet_ioctl_common(devp, cmd, arg, 1);
724 static ctl_table hpet_table[] = {
726 .ctl_name = CTL_UNNUMBERED,
727 .procname = "max-user-freq",
728 .data = &hpet_max_freq,
729 .maxlen = sizeof(int),
731 .proc_handler = &proc_dointvec,
736 static ctl_table hpet_root[] = {
738 .ctl_name = CTL_UNNUMBERED,
747 static ctl_table dev_root[] = {
758 static struct ctl_table_header *sysctl_header;
761 * Adjustment for when arming the timer with
762 * initial conditions. That is, main counter
763 * ticks expired before interrupts are enabled.
765 #define TICK_CALIBRATE (1000UL)
767 static unsigned long hpet_calibrate(struct hpets *hpetp)
769 struct hpet_timer __iomem *timer = NULL;
770 unsigned long t, m, count, i, flags, start;
771 struct hpet_dev *devp;
773 struct hpet __iomem *hpet;
775 for (j = 0, devp = hpetp->hp_dev; j < hpetp->hp_ntimer; j++, devp++)
776 if ((devp->hd_flags & HPET_OPEN) == 0) {
777 timer = devp->hd_timer;
784 hpet = hpetp->hp_hpet;
785 t = read_counter(&timer->hpet_compare);
788 count = hpet_time_div(hpetp, TICK_CALIBRATE);
790 local_irq_save(flags);
792 start = read_counter(&hpet->hpet_mc);
795 m = read_counter(&hpet->hpet_mc);
796 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
797 } while (i++, (m - start) < count);
799 local_irq_restore(flags);
801 return (m - start) / i;
804 int hpet_alloc(struct hpet_data *hdp)
807 struct hpet_dev *devp;
811 struct hpet __iomem *hpet;
812 static struct hpets *last = NULL;
813 unsigned long period;
814 unsigned long long temp;
817 * hpet_alloc can be called by platform dependent code.
818 * If platform dependent code has allocated the hpet that
819 * ACPI has also reported, then we catch it here.
821 if (hpet_is_known(hdp)) {
822 printk(KERN_DEBUG "%s: duplicate HPET ignored\n",
827 siz = sizeof(struct hpets) + ((hdp->hd_nirqs - 1) *
828 sizeof(struct hpet_dev));
830 hpetp = kzalloc(siz, GFP_KERNEL);
835 hpetp->hp_which = hpet_nhpet++;
836 hpetp->hp_hpet = hdp->hd_address;
837 hpetp->hp_hpet_phys = hdp->hd_phys_address;
839 hpetp->hp_ntimer = hdp->hd_nirqs;
841 for (i = 0; i < hdp->hd_nirqs; i++)
842 hpetp->hp_dev[i].hd_hdwirq = hdp->hd_irq[i];
844 hpet = hpetp->hp_hpet;
846 cap = readq(&hpet->hpet_cap);
848 ntimer = ((cap & HPET_NUM_TIM_CAP_MASK) >> HPET_NUM_TIM_CAP_SHIFT) + 1;
850 if (hpetp->hp_ntimer != ntimer) {
851 printk(KERN_WARNING "hpet: number irqs doesn't agree"
852 " with number of timers\n");
858 last->hp_next = hpetp;
864 period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >>
865 HPET_COUNTER_CLK_PERIOD_SHIFT; /* fs, 10^-15 */
866 temp = 1000000000000000uLL; /* 10^15 femtoseconds per second */
867 temp += period >> 1; /* round */
868 do_div(temp, period);
869 hpetp->hp_tick_freq = temp; /* ticks per second */
871 printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s",
872 hpetp->hp_which, hdp->hd_phys_address,
873 hpetp->hp_ntimer > 1 ? "s" : "");
874 for (i = 0; i < hpetp->hp_ntimer; i++)
875 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
878 printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n",
879 hpetp->hp_which, hpetp->hp_ntimer,
880 cap & HPET_COUNTER_SIZE_MASK ? 64 : 32, hpetp->hp_tick_freq);
882 mcfg = readq(&hpet->hpet_config);
883 if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) {
884 write_counter(0L, &hpet->hpet_mc);
885 mcfg |= HPET_ENABLE_CNF_MASK;
886 writeq(mcfg, &hpet->hpet_config);
889 for (i = 0, devp = hpetp->hp_dev; i < hpetp->hp_ntimer; i++, devp++) {
890 struct hpet_timer __iomem *timer;
892 timer = &hpet->hpet_timers[devp - hpetp->hp_dev];
894 devp->hd_hpets = hpetp;
895 devp->hd_hpet = hpet;
896 devp->hd_timer = timer;
899 * If the timer was reserved by platform code,
900 * then make timer unavailable for opens.
902 if (hdp->hd_state & (1 << i)) {
903 devp->hd_flags = HPET_OPEN;
907 init_waitqueue_head(&devp->hd_waitqueue);
910 hpetp->hp_delta = hpet_calibrate(hpetp);
912 if (!hpet_clocksource) {
913 hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc;
914 CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr);
915 clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq,
916 clocksource_hpet.shift);
917 clocksource_register(&clocksource_hpet);
918 hpetp->hp_clocksource = &clocksource_hpet;
919 hpet_clocksource = &clocksource_hpet;
925 static acpi_status hpet_resources(struct acpi_resource *res, void *data)
927 struct hpet_data *hdp;
929 struct acpi_resource_address64 addr;
933 status = acpi_resource_to_address64(res, &addr);
935 if (ACPI_SUCCESS(status)) {
936 hdp->hd_phys_address = addr.minimum;
937 hdp->hd_address = ioremap(addr.minimum, addr.address_length);
939 if (hpet_is_known(hdp)) {
940 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
941 __FUNCTION__, hdp->hd_phys_address);
942 iounmap(hdp->hd_address);
945 } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
946 struct acpi_resource_fixed_memory32 *fixmem32;
948 fixmem32 = &res->data.fixed_memory32;
952 hdp->hd_phys_address = fixmem32->address;
953 hdp->hd_address = ioremap(fixmem32->address,
956 if (hpet_is_known(hdp)) {
957 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
958 __FUNCTION__, hdp->hd_phys_address);
959 iounmap(hdp->hd_address);
962 } else if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) {
963 struct acpi_resource_extended_irq *irqp;
966 irqp = &res->data.extended_irq;
968 for (i = 0; i < irqp->interrupt_count; i++) {
969 irq = acpi_register_gsi(irqp->interrupts[i],
970 irqp->triggering, irqp->polarity);
974 hdp->hd_irq[hdp->hd_nirqs] = irq;
982 static int hpet_acpi_add(struct acpi_device *device)
985 struct hpet_data data;
987 memset(&data, 0, sizeof(data));
990 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
991 hpet_resources, &data);
993 if (ACPI_FAILURE(result))
996 if (!data.hd_address || !data.hd_nirqs) {
997 printk("%s: no address or irqs in _CRS\n", __FUNCTION__);
1001 return hpet_alloc(&data);
1004 static int hpet_acpi_remove(struct acpi_device *device, int type)
1006 /* XXX need to unregister clocksource, dealloc mem, etc */
1010 static const struct acpi_device_id hpet_device_ids[] = {
1014 MODULE_DEVICE_TABLE(acpi, hpet_device_ids);
1016 static struct acpi_driver hpet_acpi_driver = {
1018 .ids = hpet_device_ids,
1020 .add = hpet_acpi_add,
1021 .remove = hpet_acpi_remove,
1025 static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
1027 static int __init hpet_init(void)
1031 result = misc_register(&hpet_misc);
1035 sysctl_header = register_sysctl_table(dev_root);
1037 result = acpi_bus_register_driver(&hpet_acpi_driver);
1040 unregister_sysctl_table(sysctl_header);
1041 misc_deregister(&hpet_misc);
1048 static void __exit hpet_exit(void)
1050 acpi_bus_unregister_driver(&hpet_acpi_driver);
1053 unregister_sysctl_table(sysctl_header);
1054 misc_deregister(&hpet_misc);
1059 module_init(hpet_init);
1060 module_exit(hpet_exit);
1061 MODULE_AUTHOR("Bob Picco <Robert.Picco@hp.com>");
1062 MODULE_LICENSE("GPL");