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/config.h>
15 #include <linux/interrupt.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/miscdevice.h>
20 #include <linux/major.h>
21 #include <linux/ioport.h>
22 #include <linux/fcntl.h>
23 #include <linux/init.h>
24 #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>
32 #include <asm/current.h>
33 #include <asm/uaccess.h>
34 #include <asm/system.h>
37 #include <asm/bitops.h>
38 #include <asm/div64.h>
40 #include <linux/acpi.h>
41 #include <acpi/acpi_bus.h>
42 #include <linux/hpet.h>
45 * The High Precision Event Timer driver.
46 * This driver is closely modelled after the rtc.c driver.
47 * http://www.intel.com/labs/platcomp/hpet/hpetspec.htm
49 #define HPET_USER_FREQ (64)
50 #define HPET_DRIFT (500)
52 static u32 hpet_ntimer
, hpet_nhpet
, hpet_max_freq
= HPET_USER_FREQ
;
54 /* A lock for concurrent access by app and isr hpet activity. */
55 static spinlock_t hpet_lock
= SPIN_LOCK_UNLOCKED
;
56 /* A lock for concurrent intermodule access to hpet and isr hpet activity. */
57 static spinlock_t hpet_task_lock
= SPIN_LOCK_UNLOCKED
;
59 #define HPET_DEV_NAME (7)
62 struct hpets
*hd_hpets
;
63 struct hpet __iomem
*hd_hpet
;
64 struct hpet_timer __iomem
*hd_timer
;
65 unsigned long hd_ireqfreq
;
66 unsigned long hd_irqdata
;
67 wait_queue_head_t hd_waitqueue
;
68 struct fasync_struct
*hd_async_queue
;
69 struct hpet_task
*hd_task
;
70 unsigned int hd_flags
;
72 unsigned int hd_hdwirq
;
73 char hd_name
[HPET_DEV_NAME
];
77 struct hpets
*hp_next
;
78 struct hpet __iomem
*hp_hpet
;
79 unsigned long hp_period
;
80 unsigned long hp_delta
;
81 unsigned int hp_ntimer
;
82 unsigned int hp_which
;
83 struct hpet_dev hp_dev
[1];
86 static struct hpets
*hpets
;
88 #define HPET_OPEN 0x0001
89 #define HPET_IE 0x0002 /* interrupt enabled */
90 #define HPET_PERIODIC 0x0004
92 #if BITS_PER_LONG == 64
93 #define write_counter(V, MC) writeq(V, MC)
94 #define read_counter(MC) readq(MC)
96 #define write_counter(V, MC) writel(V, MC)
97 #define read_counter(MC) readl(MC)
101 static unsigned long long __inline
readq(void __iomem
*addr
)
103 return readl(addr
) | (((unsigned long long)readl(addr
+ 4)) << 32LL);
108 static void __inline
writeq(unsigned long long v
, void __iomem
*addr
)
110 writel(v
& 0xffffffff, addr
);
111 writel(v
>> 32, addr
+ 4);
115 static irqreturn_t
hpet_interrupt(int irq
, void *data
, struct pt_regs
*regs
)
117 struct hpet_dev
*devp
;
122 spin_lock(&hpet_lock
);
126 * For non-periodic timers, increment the accumulator.
127 * This has the effect of treating non-periodic like periodic.
129 if ((devp
->hd_flags
& (HPET_IE
| HPET_PERIODIC
)) == HPET_IE
) {
132 t
= devp
->hd_ireqfreq
;
133 m
= read_counter(&devp
->hd_hpet
->hpet_mc
);
134 write_counter(t
+ m
+ devp
->hd_hpets
->hp_delta
,
135 &devp
->hd_timer
->hpet_compare
);
138 isr
= (1 << (devp
- devp
->hd_hpets
->hp_dev
));
139 writeq(isr
, &devp
->hd_hpet
->hpet_isr
);
140 spin_unlock(&hpet_lock
);
142 spin_lock(&hpet_task_lock
);
144 devp
->hd_task
->ht_func(devp
->hd_task
->ht_data
);
145 spin_unlock(&hpet_task_lock
);
147 wake_up_interruptible(&devp
->hd_waitqueue
);
149 kill_fasync(&devp
->hd_async_queue
, SIGIO
, POLL_IN
);
154 static int hpet_open(struct inode
*inode
, struct file
*file
)
156 struct hpet_dev
*devp
;
160 if (file
->f_mode
& FMODE_WRITE
)
163 spin_lock_irq(&hpet_lock
);
165 for (devp
= NULL
, hpetp
= hpets
; hpetp
&& !devp
; hpetp
= hpetp
->hp_next
)
166 for (i
= 0; i
< hpetp
->hp_ntimer
; i
++)
167 if (hpetp
->hp_dev
[i
].hd_flags
& HPET_OPEN
168 || hpetp
->hp_dev
[i
].hd_task
)
171 devp
= &hpetp
->hp_dev
[i
];
176 spin_unlock_irq(&hpet_lock
);
180 file
->private_data
= devp
;
181 devp
->hd_irqdata
= 0;
182 devp
->hd_flags
|= HPET_OPEN
;
183 spin_unlock_irq(&hpet_lock
);
189 hpet_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
* ppos
)
191 DECLARE_WAITQUEUE(wait
, current
);
194 struct hpet_dev
*devp
;
196 devp
= file
->private_data
;
197 if (!devp
->hd_ireqfreq
)
200 if (count
< sizeof(unsigned long))
203 add_wait_queue(&devp
->hd_waitqueue
, &wait
);
206 set_current_state(TASK_INTERRUPTIBLE
);
208 spin_lock_irq(&hpet_lock
);
209 data
= devp
->hd_irqdata
;
210 devp
->hd_irqdata
= 0;
211 spin_unlock_irq(&hpet_lock
);
215 else if (file
->f_flags
& O_NONBLOCK
) {
218 } else if (signal_pending(current
)) {
219 retval
= -ERESTARTSYS
;
225 retval
= put_user(data
, (unsigned long __user
*)buf
);
227 retval
= sizeof(unsigned long);
229 __set_current_state(TASK_RUNNING
);
230 remove_wait_queue(&devp
->hd_waitqueue
, &wait
);
235 static unsigned int hpet_poll(struct file
*file
, poll_table
* wait
)
238 struct hpet_dev
*devp
;
240 devp
= file
->private_data
;
242 if (!devp
->hd_ireqfreq
)
245 poll_wait(file
, &devp
->hd_waitqueue
, wait
);
247 spin_lock_irq(&hpet_lock
);
248 v
= devp
->hd_irqdata
;
249 spin_unlock_irq(&hpet_lock
);
252 return POLLIN
| POLLRDNORM
;
257 static int hpet_mmap(struct file
*file
, struct vm_area_struct
*vma
)
259 #ifdef CONFIG_HPET_MMAP
260 struct hpet_dev
*devp
;
263 if (((vma
->vm_end
- vma
->vm_start
) != PAGE_SIZE
) || vma
->vm_pgoff
)
266 devp
= file
->private_data
;
267 addr
= (unsigned long)devp
->hd_hpet
;
269 if (addr
& (PAGE_SIZE
- 1))
272 vma
->vm_flags
|= VM_IO
;
273 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
277 (vma
, vma
->vm_start
, addr
, PAGE_SIZE
, vma
->vm_page_prot
)) {
278 printk(KERN_ERR
"remap_page_range failed in hpet.c\n");
288 static int hpet_fasync(int fd
, struct file
*file
, int on
)
290 struct hpet_dev
*devp
;
292 devp
= file
->private_data
;
294 if (fasync_helper(fd
, file
, on
, &devp
->hd_async_queue
) >= 0)
300 static int hpet_release(struct inode
*inode
, struct file
*file
)
302 struct hpet_dev
*devp
;
303 struct hpet_timer __iomem
*timer
;
306 devp
= file
->private_data
;
307 timer
= devp
->hd_timer
;
309 spin_lock_irq(&hpet_lock
);
311 writeq((readq(&timer
->hpet_config
) & ~Tn_INT_ENB_CNF_MASK
),
312 &timer
->hpet_config
);
317 devp
->hd_ireqfreq
= 0;
319 if (devp
->hd_flags
& HPET_PERIODIC
320 && readq(&timer
->hpet_config
) & Tn_TYPE_CNF_MASK
) {
323 v
= readq(&timer
->hpet_config
);
324 v
^= Tn_TYPE_CNF_MASK
;
325 writeq(v
, &timer
->hpet_config
);
328 devp
->hd_flags
&= ~(HPET_OPEN
| HPET_IE
| HPET_PERIODIC
);
329 spin_unlock_irq(&hpet_lock
);
334 if (file
->f_flags
& FASYNC
)
335 hpet_fasync(-1, file
, 0);
337 file
->private_data
= NULL
;
341 static int hpet_ioctl_common(struct hpet_dev
*, int, unsigned long, int);
344 hpet_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
347 struct hpet_dev
*devp
;
349 devp
= file
->private_data
;
350 return hpet_ioctl_common(devp
, cmd
, arg
, 0);
353 static int hpet_ioctl_ieon(struct hpet_dev
*devp
)
355 struct hpet_timer __iomem
*timer
;
356 struct hpet __iomem
*hpet
;
359 unsigned long g
, v
, t
, m
;
360 unsigned long flags
, isr
;
362 timer
= devp
->hd_timer
;
363 hpet
= devp
->hd_hpet
;
364 hpetp
= devp
->hd_hpets
;
366 v
= readq(&timer
->hpet_config
);
367 spin_lock_irq(&hpet_lock
);
369 if (devp
->hd_flags
& HPET_IE
) {
370 spin_unlock_irq(&hpet_lock
);
374 devp
->hd_flags
|= HPET_IE
;
375 spin_unlock_irq(&hpet_lock
);
377 t
= readq(&timer
->hpet_config
);
378 irq
= devp
->hd_hdwirq
;
381 sprintf(devp
->hd_name
, "hpet%d", (int)(devp
- hpetp
->hp_dev
));
384 (irq
, hpet_interrupt
, SA_INTERRUPT
, devp
->hd_name
, (void *)devp
)) {
385 printk(KERN_ERR
"hpet: IRQ %d is not free\n", irq
);
391 spin_lock_irq(&hpet_lock
);
392 devp
->hd_flags
^= HPET_IE
;
393 spin_unlock_irq(&hpet_lock
);
398 t
= devp
->hd_ireqfreq
;
399 v
= readq(&timer
->hpet_config
);
400 g
= v
| Tn_INT_ENB_CNF_MASK
;
402 if (devp
->hd_flags
& HPET_PERIODIC
) {
403 write_counter(t
, &timer
->hpet_compare
);
404 g
|= Tn_TYPE_CNF_MASK
;
405 v
|= Tn_TYPE_CNF_MASK
;
406 writeq(v
, &timer
->hpet_config
);
407 v
|= Tn_VAL_SET_CNF_MASK
;
408 writeq(v
, &timer
->hpet_config
);
409 local_irq_save(flags
);
410 m
= read_counter(&hpet
->hpet_mc
);
411 write_counter(t
+ m
+ hpetp
->hp_delta
, &timer
->hpet_compare
);
413 local_irq_save(flags
);
414 m
= read_counter(&hpet
->hpet_mc
);
415 write_counter(t
+ m
+ hpetp
->hp_delta
, &timer
->hpet_compare
);
418 isr
= (1 << (devp
- hpets
->hp_dev
));
419 writeq(isr
, &hpet
->hpet_isr
);
420 writeq(g
, &timer
->hpet_config
);
421 local_irq_restore(flags
);
426 static inline unsigned long hpet_time_div(unsigned long dis
)
428 unsigned long long m
= 1000000000000000ULL;
432 return (unsigned long)m
;
436 hpet_ioctl_common(struct hpet_dev
*devp
, int cmd
, unsigned long arg
, int kernel
)
438 struct hpet_timer __iomem
*timer
;
439 struct hpet __iomem
*hpet
;
450 timer
= devp
->hd_timer
;
451 hpet
= devp
->hd_hpet
;
452 hpetp
= devp
->hd_hpets
;
455 return hpet_ioctl_ieon(devp
);
464 if ((devp
->hd_flags
& HPET_IE
) == 0)
466 v
= readq(&timer
->hpet_config
);
467 v
&= ~Tn_INT_ENB_CNF_MASK
;
468 writeq(v
, &timer
->hpet_config
);
470 free_irq(devp
->hd_irq
, devp
);
473 devp
->hd_flags
^= HPET_IE
;
477 struct hpet_info info
;
479 info
.hi_ireqfreq
= hpet_time_div(hpetp
->hp_period
*
482 readq(&timer
->hpet_config
) & Tn_PER_INT_CAP_MASK
;
483 info
.hi_hpet
= devp
->hd_hpets
->hp_which
;
484 info
.hi_timer
= devp
- devp
->hd_hpets
->hp_dev
;
485 if (copy_to_user((void __user
*)arg
, &info
, sizeof(info
)))
490 v
= readq(&timer
->hpet_config
);
491 if ((v
& Tn_PER_INT_CAP_MASK
) == 0) {
495 devp
->hd_flags
|= HPET_PERIODIC
;
498 v
= readq(&timer
->hpet_config
);
499 if ((v
& Tn_PER_INT_CAP_MASK
) == 0) {
503 if (devp
->hd_flags
& HPET_PERIODIC
&&
504 readq(&timer
->hpet_config
) & Tn_TYPE_CNF_MASK
) {
505 v
= readq(&timer
->hpet_config
);
506 v
^= Tn_TYPE_CNF_MASK
;
507 writeq(v
, &timer
->hpet_config
);
509 devp
->hd_flags
&= ~HPET_PERIODIC
;
512 if (!kernel
&& (arg
> hpet_max_freq
) &&
513 !capable(CAP_SYS_RESOURCE
)) {
518 if (arg
& (arg
- 1)) {
523 devp
->hd_ireqfreq
= hpet_time_div(hpetp
->hp_period
* arg
);
529 static struct file_operations hpet_fops
= {
530 .owner
= THIS_MODULE
,
536 .release
= hpet_release
,
537 .fasync
= hpet_fasync
,
541 EXPORT_SYMBOL(hpet_alloc
);
542 EXPORT_SYMBOL(hpet_register
);
543 EXPORT_SYMBOL(hpet_unregister
);
544 EXPORT_SYMBOL(hpet_control
);
546 int hpet_register(struct hpet_task
*tp
, int periodic
)
550 struct hpet_timer __iomem
*timer
;
551 struct hpet_dev
*devp
;
556 mask
= Tn_PER_INT_CAP_MASK
;
565 spin_lock_irq(&hpet_task_lock
);
566 spin_lock(&hpet_lock
);
568 for (devp
= NULL
, hpetp
= hpets
; hpetp
&& !devp
; hpetp
= hpetp
->hp_next
)
569 for (timer
= hpetp
->hp_hpet
->hpet_timers
, i
= 0;
570 i
< hpetp
->hp_ntimer
; i
++, timer
++) {
571 if ((readq(&timer
->hpet_config
) & Tn_PER_INT_CAP_MASK
)
575 devp
= &hpetp
->hp_dev
[i
];
577 if (devp
->hd_flags
& HPET_OPEN
|| devp
->hd_task
) {
582 tp
->ht_opaque
= devp
;
587 spin_unlock(&hpet_lock
);
588 spin_unlock_irq(&hpet_task_lock
);
596 static inline int hpet_tpcheck(struct hpet_task
*tp
)
598 struct hpet_dev
*devp
;
601 devp
= tp
->ht_opaque
;
606 for (hpetp
= hpets
; hpetp
; hpetp
= hpetp
->hp_next
)
607 if (devp
>= hpetp
->hp_dev
608 && devp
< (hpetp
->hp_dev
+ hpetp
->hp_ntimer
)
609 && devp
->hd_hpet
== hpetp
->hp_hpet
)
615 int hpet_unregister(struct hpet_task
*tp
)
617 struct hpet_dev
*devp
;
618 struct hpet_timer __iomem
*timer
;
621 if ((err
= hpet_tpcheck(tp
)))
624 spin_lock_irq(&hpet_task_lock
);
625 spin_lock(&hpet_lock
);
627 devp
= tp
->ht_opaque
;
628 if (devp
->hd_task
!= tp
) {
629 spin_unlock(&hpet_lock
);
630 spin_unlock_irq(&hpet_task_lock
);
634 timer
= devp
->hd_timer
;
635 writeq((readq(&timer
->hpet_config
) & ~Tn_INT_ENB_CNF_MASK
),
636 &timer
->hpet_config
);
637 devp
->hd_flags
&= ~(HPET_IE
| HPET_PERIODIC
);
638 devp
->hd_task
= NULL
;
639 spin_unlock(&hpet_lock
);
640 spin_unlock_irq(&hpet_task_lock
);
645 int hpet_control(struct hpet_task
*tp
, unsigned int cmd
, unsigned long arg
)
647 struct hpet_dev
*devp
;
650 if ((err
= hpet_tpcheck(tp
)))
653 spin_lock_irq(&hpet_lock
);
654 devp
= tp
->ht_opaque
;
655 if (devp
->hd_task
!= tp
) {
656 spin_unlock_irq(&hpet_lock
);
659 spin_unlock_irq(&hpet_lock
);
660 return hpet_ioctl_common(devp
, cmd
, arg
, 1);
663 #ifdef CONFIG_TIME_INTERPOLATION
665 static struct time_interpolator hpet_interpolator
= {
666 .source
= TIME_SOURCE_MMIO64
,
672 static ctl_table hpet_table
[] = {
675 .procname
= "max-user-freq",
676 .data
= &hpet_max_freq
,
677 .maxlen
= sizeof(int),
679 .proc_handler
= &proc_dointvec
,
684 static ctl_table hpet_root
[] = {
695 static ctl_table dev_root
[] = {
706 static struct ctl_table_header
*sysctl_header
;
709 * Adjustment for when arming the timer with
710 * initial conditions. That is, main counter
711 * ticks expired before interrupts are enabled.
713 #define TICK_CALIBRATE (1000UL)
715 static unsigned long __init
hpet_calibrate(struct hpets
*hpetp
)
717 struct hpet_timer __iomem
*timer
= NULL
;
718 unsigned long t
, m
, count
, i
, flags
, start
;
719 struct hpet_dev
*devp
;
721 struct hpet __iomem
*hpet
;
723 for (j
= 0, devp
= hpetp
->hp_dev
; j
< hpetp
->hp_ntimer
; j
++, devp
++)
724 if ((devp
->hd_flags
& HPET_OPEN
) == 0) {
725 timer
= devp
->hd_timer
;
732 hpet
= hpets
->hp_hpet
;
733 t
= read_counter(&timer
->hpet_compare
);
736 count
= hpet_time_div(hpetp
->hp_period
* TICK_CALIBRATE
);
738 local_irq_save(flags
);
740 start
= read_counter(&hpet
->hpet_mc
);
743 m
= read_counter(&hpet
->hpet_mc
);
744 write_counter(t
+ m
+ hpetp
->hp_delta
, &timer
->hpet_compare
);
745 } while (i
++, (m
- start
) < count
);
747 local_irq_restore(flags
);
749 return (m
- start
) / i
;
752 int __init
hpet_alloc(struct hpet_data
*hdp
)
755 struct hpet_dev
*devp
;
759 struct hpet __iomem
*hpet
;
760 static struct hpets
*last __initdata
= (struct hpets
*)0;
764 * hpet_alloc can be called by platform dependent code.
765 * if platform dependent code has allocated the hpet
766 * ACPI also reports hpet, then we catch it here.
768 for (hpetp
= hpets
; hpetp
; hpetp
= hpetp
->hp_next
)
769 if (hpetp
->hp_hpet
== hdp
->hd_address
)
772 siz
= sizeof(struct hpets
) + ((hdp
->hd_nirqs
- 1) *
773 sizeof(struct hpet_dev
));
775 hpetp
= kmalloc(siz
, GFP_KERNEL
);
780 memset(hpetp
, 0, siz
);
782 hpetp
->hp_which
= hpet_nhpet
++;
783 hpetp
->hp_hpet
= hdp
->hd_address
;
785 hpetp
->hp_ntimer
= hdp
->hd_nirqs
;
787 for (i
= 0; i
< hdp
->hd_nirqs
; i
++)
788 hpetp
->hp_dev
[i
].hd_hdwirq
= hdp
->hd_irq
[i
];
790 hpet
= hpetp
->hp_hpet
;
792 cap
= readq(&hpet
->hpet_cap
);
794 ntimer
= ((cap
& HPET_NUM_TIM_CAP_MASK
) >> HPET_NUM_TIM_CAP_SHIFT
) + 1;
796 if (hpetp
->hp_ntimer
!= ntimer
) {
797 printk(KERN_WARNING
"hpet: number irqs doesn't agree"
798 " with number of timers\n");
804 last
->hp_next
= hpetp
;
810 hpetp
->hp_period
= (cap
& HPET_COUNTER_CLK_PERIOD_MASK
) >>
811 HPET_COUNTER_CLK_PERIOD_SHIFT
;
813 printk(KERN_INFO
"hpet%d: at MMIO 0x%p, IRQ%s",
814 hpetp
->hp_which
, hpet
, hpetp
->hp_ntimer
> 1 ? "s" : "");
815 for (i
= 0; i
< hpetp
->hp_ntimer
; i
++)
816 printk("%s %d", i
> 0 ? "," : "", hdp
->hd_irq
[i
]);
819 ns
= hpetp
->hp_period
; /* femptoseconds, 10^-15 */
820 do_div(ns
, 1000000); /* convert to nanoseconds, 10^-9 */
821 printk(KERN_INFO
"hpet%d: %ldns tick, %d %d-bit timers\n",
822 hpetp
->hp_which
, ns
, hpetp
->hp_ntimer
,
823 cap
& HPET_COUNTER_SIZE_MASK
? 64 : 32);
825 mcfg
= readq(&hpet
->hpet_config
);
826 if ((mcfg
& HPET_ENABLE_CNF_MASK
) == 0) {
827 write_counter(0L, &hpet
->hpet_mc
);
828 mcfg
|= HPET_ENABLE_CNF_MASK
;
829 writeq(mcfg
, &hpet
->hpet_config
);
832 for (i
= 0, devp
= hpetp
->hp_dev
; i
< hpetp
->hp_ntimer
;
833 i
++, hpet_ntimer
++, devp
++) {
835 struct hpet_timer __iomem
*timer
;
837 timer
= &hpet
->hpet_timers
[devp
- hpetp
->hp_dev
];
838 v
= readq(&timer
->hpet_config
);
840 devp
->hd_hpets
= hpetp
;
841 devp
->hd_hpet
= hpet
;
842 devp
->hd_timer
= timer
;
845 * If the timer was reserved by platform code,
846 * then make timer unavailable for opens.
848 if (hdp
->hd_state
& (1 << i
)) {
849 devp
->hd_flags
= HPET_OPEN
;
853 init_waitqueue_head(&devp
->hd_waitqueue
);
856 hpetp
->hp_delta
= hpet_calibrate(hpetp
);
861 static acpi_status __init
hpet_resources(struct acpi_resource
*res
, void *data
)
863 struct hpet_data
*hdp
;
865 struct acpi_resource_address64 addr
;
870 status
= acpi_resource_to_address64(res
, &addr
);
872 if (ACPI_SUCCESS(status
)) {
875 size
= addr
.max_address_range
- addr
.min_address_range
+ 1;
876 hdp
->hd_address
= ioremap(addr
.min_address_range
, size
);
878 for (hpetp
= hpets
; hpetp
; hpetp
= hpetp
->hp_next
)
879 if (hpetp
->hp_hpet
== hdp
->hd_address
)
881 } else if (res
->id
== ACPI_RSTYPE_EXT_IRQ
) {
882 struct acpi_resource_ext_irq
*irqp
;
885 irqp
= &res
->data
.extended_irq
;
887 if (irqp
->number_of_interrupts
> 0) {
888 hdp
->hd_nirqs
= irqp
->number_of_interrupts
;
890 for (i
= 0; i
< hdp
->hd_nirqs
; i
++)
892 acpi_register_gsi(irqp
->interrupts
[i
],
894 irqp
->active_high_low
);
901 static int __init
hpet_acpi_add(struct acpi_device
*device
)
904 struct hpet_data data
;
906 memset(&data
, 0, sizeof(data
));
909 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
,
910 hpet_resources
, &data
);
912 if (ACPI_FAILURE(result
))
915 if (!data
.hd_address
|| !data
.hd_nirqs
) {
916 printk("%s: no address or irqs in _CRS\n", __FUNCTION__
);
920 return hpet_alloc(&data
);
923 static int __init
hpet_acpi_remove(struct acpi_device
*device
, int type
)
928 static struct acpi_driver hpet_acpi_driver
= {
932 .add
= hpet_acpi_add
,
933 .remove
= hpet_acpi_remove
,
937 static struct miscdevice hpet_misc
= { HPET_MINOR
, "hpet", &hpet_fops
};
939 static int __init
hpet_init(void)
941 (void)acpi_bus_register_driver(&hpet_acpi_driver
);
944 if (misc_register(&hpet_misc
))
947 sysctl_header
= register_sysctl_table(dev_root
, 0);
949 #ifdef CONFIG_TIME_INTERPOLATION
953 hpet
= hpets
->hp_hpet
;
954 hpet_interpolator
.addr
= &hpets
->hp_hpet
->hpet_mc
;
955 hpet_interpolator
.frequency
= hpet_time_div(hpets
->hp_period
);
956 hpet_interpolator
.drift
= hpet_interpolator
.frequency
*
957 HPET_DRIFT
/ 1000000;
958 register_time_interpolator(&hpet_interpolator
);
966 static void __exit
hpet_exit(void)
968 acpi_bus_unregister_driver(&hpet_acpi_driver
);
971 unregister_sysctl_table(sysctl_header
);
976 module_init(hpet_init
);
977 module_exit(hpet_exit
);
978 MODULE_AUTHOR("Bob Picco <Robert.Picco@hp.com>");
979 MODULE_LICENSE("GPL");