include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / char / hpet.c
index 5172d4e..9ded667 100644 (file)
  * published by the Free Software Foundation.
  */
 
-#include <linux/config.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/miscdevice.h>
 #include <linux/major.h>
@@ -22,6 +22,7 @@
 #include <linux/fcntl.h>
 #include <linux/init.h>
 #include <linux/poll.h>
+#include <linux/mm.h>
 #include <linux/proc_fs.h>
 #include <linux/spinlock.h>
 #include <linux/sysctl.h>
@@ -29,6 +30,8 @@
 #include <linux/bcd.h>
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
+#include <linux/clocksource.h>
+#include <linux/slab.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
 /*
  * The High Precision Event Timer driver.
  * This driver is closely modelled after the rtc.c driver.
- * http://www.intel.com/hardwaredesign/hpetspec.htm
+ * http://www.intel.com/hardwaredesign/hpetspec_1.pdf
  */
 #define        HPET_USER_FREQ  (64)
 #define        HPET_DRIFT      (500)
 
 #define HPET_RANGE_SIZE                1024    /* from HPET spec */
 
+
+/* WARNING -- don't get confused.  These macros are never used
+ * to write the (single) counter, and rarely to read it.
+ * They're badly named; to fix, someday.
+ */
+#if BITS_PER_LONG == 64
+#define        write_counter(V, MC)    writeq(V, MC)
+#define        read_counter(MC)        readq(MC)
+#else
+#define        write_counter(V, MC)    writel(V, MC)
+#define        read_counter(MC)        readl(MC)
+#endif
+
 static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
 
+/* This clocksource driver currently only works on ia64 */
+#ifdef CONFIG_IA64
+static void __iomem *hpet_mctr;
+
+static cycle_t read_hpet(struct clocksource *cs)
+{
+       return (cycle_t)read_counter((void __iomem *)hpet_mctr);
+}
+
+static struct clocksource clocksource_hpet = {
+        .name           = "hpet",
+        .rating         = 250,
+        .read           = read_hpet,
+        .mask           = CLOCKSOURCE_MASK(64),
+       .mult           = 0, /* to be calculated */
+        .shift          = 10,
+        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+static struct clocksource *hpet_clocksource;
+#endif
+
 /* A lock for concurrent access by app and isr hpet activity. */
 static DEFINE_SPINLOCK(hpet_lock);
-/* A lock for concurrent intermodule access to hpet and isr hpet activity. */
-static DEFINE_SPINLOCK(hpet_task_lock);
 
 #define        HPET_DEV_NAME   (7)
 
@@ -68,7 +103,6 @@ struct hpet_dev {
        unsigned long hd_irqdata;
        wait_queue_head_t hd_waitqueue;
        struct fasync_struct *hd_async_queue;
-       struct hpet_task *hd_task;
        unsigned int hd_flags;
        unsigned int hd_irq;
        unsigned int hd_hdwirq;
@@ -79,7 +113,7 @@ struct hpets {
        struct hpets *hp_next;
        struct hpet __iomem *hp_hpet;
        unsigned long hp_hpet_phys;
-       struct time_interpolator *hp_interpolator;
+       struct clocksource *hp_clocksource;
        unsigned long long hp_tick_freq;
        unsigned long hp_delta;
        unsigned int hp_ntimer;
@@ -94,13 +128,6 @@ static struct hpets *hpets;
 #define        HPET_PERIODIC           0x0004
 #define        HPET_SHARED_IRQ         0x0008
 
-#if BITS_PER_LONG == 64
-#define        write_counter(V, MC)    writeq(V, MC)
-#define        read_counter(MC)        readq(MC)
-#else
-#define        write_counter(V, MC)    writel(V, MC)
-#define        read_counter(MC)        readl(MC)
-#endif
 
 #ifndef readq
 static inline unsigned long long readq(void __iomem *addr)
@@ -117,7 +144,7 @@ static inline void writeq(unsigned long long v, void __iomem *addr)
 }
 #endif
 
-static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs)
+static irqreturn_t hpet_interrupt(int irq, void *data)
 {
        struct hpet_dev *devp;
        unsigned long isr;
@@ -140,20 +167,14 @@ static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs)
                unsigned long m, t;
 
                t = devp->hd_ireqfreq;
-               m = read_counter(&devp->hd_hpet->hpet_mc);
-               write_counter(t + m + devp->hd_hpets->hp_delta,
-                             &devp->hd_timer->hpet_compare);
+               m = read_counter(&devp->hd_timer->hpet_compare);
+               write_counter(t + m, &devp->hd_timer->hpet_compare);
        }
 
        if (devp->hd_flags & HPET_SHARED_IRQ)
                writel(isr, &devp->hd_hpet->hpet_isr);
        spin_unlock(&hpet_lock);
 
-       spin_lock(&hpet_task_lock);
-       if (devp->hd_task)
-               devp->hd_task->ht_func(devp->hd_task->ht_data);
-       spin_unlock(&hpet_task_lock);
-
        wake_up_interruptible(&devp->hd_waitqueue);
 
        kill_fasync(&devp->hd_async_queue, SIGIO, POLL_IN);
@@ -161,6 +182,65 @@ static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
+static void hpet_timer_set_irq(struct hpet_dev *devp)
+{
+       unsigned long v;
+       int irq, gsi;
+       struct hpet_timer __iomem *timer;
+
+       spin_lock_irq(&hpet_lock);
+       if (devp->hd_hdwirq) {
+               spin_unlock_irq(&hpet_lock);
+               return;
+       }
+
+       timer = devp->hd_timer;
+
+       /* we prefer level triggered mode */
+       v = readl(&timer->hpet_config);
+       if (!(v & Tn_INT_TYPE_CNF_MASK)) {
+               v |= Tn_INT_TYPE_CNF_MASK;
+               writel(v, &timer->hpet_config);
+       }
+       spin_unlock_irq(&hpet_lock);
+
+       v = (readq(&timer->hpet_config) & Tn_INT_ROUTE_CAP_MASK) >>
+                                Tn_INT_ROUTE_CAP_SHIFT;
+
+       /*
+        * In PIC mode, skip IRQ0-4, IRQ6-9, IRQ12-15 which is always used by
+        * legacy device. In IO APIC mode, we skip all the legacy IRQS.
+        */
+       if (acpi_irq_model == ACPI_IRQ_MODEL_PIC)
+               v &= ~0xf3df;
+       else
+               v &= ~0xffff;
+
+       for_each_set_bit(irq, &v, HPET_MAX_IRQ) {
+               if (irq >= nr_irqs) {
+                       irq = HPET_MAX_IRQ;
+                       break;
+               }
+
+               gsi = acpi_register_gsi(NULL, irq, ACPI_LEVEL_SENSITIVE,
+                                       ACPI_ACTIVE_LOW);
+               if (gsi > 0)
+                       break;
+
+               /* FIXME: Setup interrupt source table */
+       }
+
+       if (irq < HPET_MAX_IRQ) {
+               spin_lock_irq(&hpet_lock);
+               v = readl(&timer->hpet_config);
+               v |= irq << Tn_INT_ROUTE_CNF_SHIFT;
+               writel(v, &timer->hpet_config);
+               devp->hd_hdwirq = gsi;
+               spin_unlock_irq(&hpet_lock);
+       }
+       return;
+}
+
 static int hpet_open(struct inode *inode, struct file *file)
 {
        struct hpet_dev *devp;
@@ -170,12 +250,12 @@ static int hpet_open(struct inode *inode, struct file *file)
        if (file->f_mode & FMODE_WRITE)
                return -EINVAL;
 
+       lock_kernel();
        spin_lock_irq(&hpet_lock);
 
        for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
                for (i = 0; i < hpetp->hp_ntimer; i++)
-                       if (hpetp->hp_dev[i].hd_flags & HPET_OPEN
-                           || hpetp->hp_dev[i].hd_task)
+                       if (hpetp->hp_dev[i].hd_flags & HPET_OPEN)
                                continue;
                        else {
                                devp = &hpetp->hp_dev[i];
@@ -184,6 +264,7 @@ static int hpet_open(struct inode *inode, struct file *file)
 
        if (!devp) {
                spin_unlock_irq(&hpet_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -191,6 +272,9 @@ static int hpet_open(struct inode *inode, struct file *file)
        devp->hd_irqdata = 0;
        devp->hd_flags |= HPET_OPEN;
        spin_unlock_irq(&hpet_lock);
+       unlock_kernel();
+
+       hpet_timer_set_irq(devp);
 
        return 0;
 }
@@ -285,7 +369,7 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
        if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
                                        PAGE_SIZE, vma->vm_page_prot)) {
                printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
-                       __FUNCTION__);
+                       __func__);
                return -EAGAIN;
        }
 
@@ -341,9 +425,6 @@ static int hpet_release(struct inode *inode, struct file *file)
        if (irq)
                free_irq(irq, devp);
 
-       if (file->f_flags & FASYNC)
-               hpet_fasync(-1, file, 0);
-
        file->private_data = NULL;
        return 0;
 }
@@ -396,7 +477,7 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
 
                sprintf(devp->hd_name, "hpet%d", (int)(devp - hpetp->hp_dev));
                irq_flags = devp->hd_flags & HPET_SHARED_IRQ
-                                               ? SA_SHIRQ : SA_INTERRUPT;
+                                               ? IRQF_SHARED : IRQF_DISABLED;
                if (request_irq(irq, hpet_interrupt, irq_flags,
                                devp->hd_name, (void *)devp)) {
                        printk(KERN_ERR "hpet: IRQ %d is not free\n", irq);
@@ -414,18 +495,32 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
        devp->hd_irq = irq;
        t = devp->hd_ireqfreq;
        v = readq(&timer->hpet_config);
-       g = v | Tn_INT_ENB_CNF_MASK;
+
+       /* 64-bit comparators are not yet supported through the ioctls,
+        * so force this into 32-bit mode if it supports both modes
+        */
+       g = v | Tn_32MODE_CNF_MASK | Tn_INT_ENB_CNF_MASK;
 
        if (devp->hd_flags & HPET_PERIODIC) {
-               write_counter(t, &timer->hpet_compare);
                g |= Tn_TYPE_CNF_MASK;
-               v |= Tn_TYPE_CNF_MASK;
-               writeq(v, &timer->hpet_config);
-               v |= Tn_VAL_SET_CNF_MASK;
+               v |= Tn_TYPE_CNF_MASK | Tn_VAL_SET_CNF_MASK;
                writeq(v, &timer->hpet_config);
                local_irq_save(flags);
+
+               /*
+                * NOTE: First we modify the hidden accumulator
+                * register supported by periodic-capable comparators.
+                * We never want to modify the (single) counter; that
+                * would affect all the comparators. The value written
+                * is the counter value when the first interrupt is due.
+                */
                m = read_counter(&hpet->hpet_mc);
                write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
+               /*
+                * Then we modify the comparator, indicating the period
+                * for subsequent interrupt.
+                */
+               write_counter(t, &timer->hpet_compare);
        } else {
                local_irq_save(flags);
                m = read_counter(&hpet->hpet_mc);
@@ -554,7 +649,7 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
        return err;
 }
 
-static struct file_operations hpet_fops = {
+static const struct file_operations hpet_fops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .read = hpet_read,
@@ -577,187 +672,39 @@ static int hpet_is_known(struct hpet_data *hdp)
        return 0;
 }
 
-EXPORT_SYMBOL(hpet_alloc);
-EXPORT_SYMBOL(hpet_register);
-EXPORT_SYMBOL(hpet_unregister);
-EXPORT_SYMBOL(hpet_control);
-
-int hpet_register(struct hpet_task *tp, int periodic)
-{
-       unsigned int i;
-       u64 mask;
-       struct hpet_timer __iomem *timer;
-       struct hpet_dev *devp;
-       struct hpets *hpetp;
-
-       switch (periodic) {
-       case 1:
-               mask = Tn_PER_INT_CAP_MASK;
-               break;
-       case 0:
-               mask = 0;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       tp->ht_opaque = NULL;
-
-       spin_lock_irq(&hpet_task_lock);
-       spin_lock(&hpet_lock);
-
-       for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
-               for (timer = hpetp->hp_hpet->hpet_timers, i = 0;
-                    i < hpetp->hp_ntimer; i++, timer++) {
-                       if ((readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK)
-                           != mask)
-                               continue;
-
-                       devp = &hpetp->hp_dev[i];
-
-                       if (devp->hd_flags & HPET_OPEN || devp->hd_task) {
-                               devp = NULL;
-                               continue;
-                       }
-
-                       tp->ht_opaque = devp;
-                       devp->hd_task = tp;
-                       break;
-               }
-
-       spin_unlock(&hpet_lock);
-       spin_unlock_irq(&hpet_task_lock);
-
-       if (tp->ht_opaque)
-               return 0;
-       else
-               return -EBUSY;
-}
-
-static inline int hpet_tpcheck(struct hpet_task *tp)
-{
-       struct hpet_dev *devp;
-       struct hpets *hpetp;
-
-       devp = tp->ht_opaque;
-
-       if (!devp)
-               return -ENXIO;
-
-       for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
-               if (devp >= hpetp->hp_dev
-                   && devp < (hpetp->hp_dev + hpetp->hp_ntimer)
-                   && devp->hd_hpet == hpetp->hp_hpet)
-                       return 0;
-
-       return -ENXIO;
-}
-
-int hpet_unregister(struct hpet_task *tp)
-{
-       struct hpet_dev *devp;
-       struct hpet_timer __iomem *timer;
-       int err;
-
-       if ((err = hpet_tpcheck(tp)))
-               return err;
-
-       spin_lock_irq(&hpet_task_lock);
-       spin_lock(&hpet_lock);
-
-       devp = tp->ht_opaque;
-       if (devp->hd_task != tp) {
-               spin_unlock(&hpet_lock);
-               spin_unlock_irq(&hpet_task_lock);
-               return -ENXIO;
-       }
-
-       timer = devp->hd_timer;
-       writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK),
-              &timer->hpet_config);
-       devp->hd_flags &= ~(HPET_IE | HPET_PERIODIC);
-       devp->hd_task = NULL;
-       spin_unlock(&hpet_lock);
-       spin_unlock_irq(&hpet_task_lock);
-
-       return 0;
-}
-
-int hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg)
-{
-       struct hpet_dev *devp;
-       int err;
-
-       if ((err = hpet_tpcheck(tp)))
-               return err;
-
-       spin_lock_irq(&hpet_lock);
-       devp = tp->ht_opaque;
-       if (devp->hd_task != tp) {
-               spin_unlock_irq(&hpet_lock);
-               return -ENXIO;
-       }
-       spin_unlock_irq(&hpet_lock);
-       return hpet_ioctl_common(devp, cmd, arg, 1);
-}
-
 static ctl_table hpet_table[] = {
        {
-        .ctl_name = 1,
         .procname = "max-user-freq",
         .data = &hpet_max_freq,
         .maxlen = sizeof(int),
         .mode = 0644,
-        .proc_handler = &proc_dointvec,
+        .proc_handler = proc_dointvec,
         },
-       {.ctl_name = 0}
+       {}
 };
 
 static ctl_table hpet_root[] = {
        {
-        .ctl_name = 1,
         .procname = "hpet",
         .maxlen = 0,
         .mode = 0555,
         .child = hpet_table,
         },
-       {.ctl_name = 0}
+       {}
 };
 
 static ctl_table dev_root[] = {
        {
-        .ctl_name = CTL_DEV,
         .procname = "dev",
         .maxlen = 0,
         .mode = 0555,
         .child = hpet_root,
         },
-       {.ctl_name = 0}
+       {}
 };
 
 static struct ctl_table_header *sysctl_header;
 
-static void hpet_register_interpolator(struct hpets *hpetp)
-{
-#ifdef CONFIG_TIME_INTERPOLATION
-       struct time_interpolator *ti;
-
-       ti = kzalloc(sizeof(*ti), GFP_KERNEL);
-       if (!ti)
-               return;
-
-       ti->source = TIME_SOURCE_MMIO64;
-       ti->shift = 10;
-       ti->addr = &hpetp->hp_hpet->hpet_mc;
-       ti->frequency = hpetp->hp_tick_freq;
-       ti->drift = HPET_DRIFT;
-       ti->mask = -1;
-
-       hpetp->hp_interpolator = ti;
-       register_time_interpolator(ti);
-#endif
-}
-
 /*
  * Adjustment for when arming the timer with
  * initial conditions.  That is, main counter
@@ -765,7 +712,7 @@ static void hpet_register_interpolator(struct hpets *hpetp)
  */
 #define        TICK_CALIBRATE  (1000UL)
 
-static unsigned long hpet_calibrate(struct hpets *hpetp)
+static unsigned long __hpet_calibrate(struct hpets *hpetp)
 {
        struct hpet_timer __iomem *timer = NULL;
        unsigned long t, m, count, i, flags, start;
@@ -802,6 +749,26 @@ static unsigned long hpet_calibrate(struct hpets *hpetp)
        return (m - start) / i;
 }
 
+static unsigned long hpet_calibrate(struct hpets *hpetp)
+{
+       unsigned long ret = -1;
+       unsigned long tmp;
+
+       /*
+        * Try to calibrate until return value becomes stable small value.
+        * If SMI interruption occurs in calibration loop, the return value
+        * will be big. This avoids its impact.
+        */
+       for ( ; ; ) {
+               tmp = __hpet_calibrate(hpetp);
+               if (ret <= tmp)
+                       break;
+               ret = tmp;
+       }
+
+       return ret;
+}
+
 int hpet_alloc(struct hpet_data *hdp)
 {
        u64 cap, mcfg;
@@ -813,6 +780,7 @@ int hpet_alloc(struct hpet_data *hdp)
        static struct hpets *last = NULL;
        unsigned long period;
        unsigned long long temp;
+       u32 remainder;
 
        /*
         * hpet_alloc can be called by platform dependent code.
@@ -821,7 +789,7 @@ int hpet_alloc(struct hpet_data *hdp)
         */
        if (hpet_is_known(hdp)) {
                printk(KERN_DEBUG "%s: duplicate HPET ignored\n",
-                       __FUNCTION__);
+                       __func__);
                return 0;
        }
 
@@ -869,16 +837,20 @@ int hpet_alloc(struct hpet_data *hdp)
        do_div(temp, period);
        hpetp->hp_tick_freq = temp; /* ticks per second */
 
-       printk(KERN_INFO "hpet%d: at MMIO 0x%lx (virtual 0x%p), IRQ%s",
-               hpetp->hp_which, hdp->hd_phys_address, hdp->hd_address,
+       printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s",
+               hpetp->hp_which, hdp->hd_phys_address,
                hpetp->hp_ntimer > 1 ? "s" : "");
        for (i = 0; i < hpetp->hp_ntimer; i++)
                printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
        printk("\n");
 
-       printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n",
-              hpetp->hp_which, hpetp->hp_ntimer,
-              cap & HPET_COUNTER_SIZE_MASK ? 64 : 32, hpetp->hp_tick_freq);
+       temp = hpetp->hp_tick_freq;
+       remainder = do_div(temp, 1000000);
+       printk(KERN_INFO
+               "hpet%u: %u comparators, %d-bit %u.%06u MHz counter\n",
+               hpetp->hp_which, hpetp->hp_ntimer,
+               cap & HPET_COUNTER_SIZE_MASK ? 64 : 32,
+               (unsigned) temp, remainder);
 
        mcfg = readq(&hpet->hpet_config);
        if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) {
@@ -909,7 +881,19 @@ int hpet_alloc(struct hpet_data *hdp)
        }
 
        hpetp->hp_delta = hpet_calibrate(hpetp);
-       hpet_register_interpolator(hpetp);
+
+/* This clocksource driver currently only works on ia64 */
+#ifdef CONFIG_IA64
+       if (!hpet_clocksource) {
+               hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc;
+               CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr);
+               clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq,
+                                               clocksource_hpet.shift);
+               clocksource_register(&clocksource_hpet);
+               hpetp->hp_clocksource = &clocksource_hpet;
+               hpet_clocksource = &clocksource_hpet;
+       }
+#endif
 
        return 0;
 }
@@ -925,53 +909,42 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
        status = acpi_resource_to_address64(res, &addr);
 
        if (ACPI_SUCCESS(status)) {
-               unsigned long size;
-
-               size = addr.max_address_range - addr.min_address_range + 1;
-               hdp->hd_phys_address = addr.min_address_range;
-               hdp->hd_address = ioremap(addr.min_address_range, size);
+               hdp->hd_phys_address = addr.minimum;
+               hdp->hd_address = ioremap(addr.minimum, addr.address_length);
 
                if (hpet_is_known(hdp)) {
-                       printk(KERN_DEBUG "%s: 0x%lx is busy\n",
-                               __FUNCTION__, hdp->hd_phys_address);
                        iounmap(hdp->hd_address);
-                       return -EBUSY;
+                       return AE_ALREADY_EXISTS;
                }
-       } else if (res->type == ACPI_RSTYPE_FIXED_MEM32) {
-               struct acpi_resource_fixed_mem32 *fixmem32;
+       } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
+               struct acpi_resource_fixed_memory32 *fixmem32;
 
                fixmem32 = &res->data.fixed_memory32;
                if (!fixmem32)
-                       return -EINVAL;
+                       return AE_NO_MEMORY;
 
-               hdp->hd_phys_address = fixmem32->range_base_address;
-               hdp->hd_address = ioremap(fixmem32->range_base_address,
+               hdp->hd_phys_address = fixmem32->address;
+               hdp->hd_address = ioremap(fixmem32->address,
                                                HPET_RANGE_SIZE);
 
                if (hpet_is_known(hdp)) {
-                       printk(KERN_DEBUG "%s: 0x%lx is busy\n",
-                               __FUNCTION__, hdp->hd_phys_address);
                        iounmap(hdp->hd_address);
-                       return -EBUSY;
+                       return AE_ALREADY_EXISTS;
                }
-       } else if (res->type == ACPI_RSTYPE_EXT_IRQ) {
-               struct acpi_resource_ext_irq *irqp;
-               int i;
+       } else if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) {
+               struct acpi_resource_extended_irq *irqp;
+               int i, irq;
 
                irqp = &res->data.extended_irq;
 
-               if (irqp->number_of_interrupts > 0) {
-                       hdp->hd_nirqs = irqp->number_of_interrupts;
-
-                       for (i = 0; i < hdp->hd_nirqs; i++) {
-                               int rc =
-                                   acpi_register_gsi(irqp->interrupts[i],
-                                                     irqp->edge_level,
-                                                     irqp->active_high_low);
-                               if (rc < 0)
-                                       return AE_ERROR;
-                               hdp->hd_irq[i] = rc;
-                       }
+               for (i = 0; i < irqp->interrupt_count; i++) {
+                       irq = acpi_register_gsi(NULL, irqp->interrupts[i],
+                                     irqp->triggering, irqp->polarity);
+                       if (irq < 0)
+                               return AE_ERROR;
+
+                       hdp->hd_irq[hdp->hd_nirqs] = irq;
+                       hdp->hd_nirqs++;
                }
        }
 
@@ -993,7 +966,7 @@ static int hpet_acpi_add(struct acpi_device *device)
                return -ENODEV;
 
        if (!data.hd_address || !data.hd_nirqs) {
-               printk("%s: no address or irqs in _CRS\n", __FUNCTION__);
+               printk("%s: no address or irqs in _CRS\n", __func__);
                return -ENODEV;
        }
 
@@ -1002,13 +975,19 @@ static int hpet_acpi_add(struct acpi_device *device)
 
 static int hpet_acpi_remove(struct acpi_device *device, int type)
 {
-       /* XXX need to unregister interpolator, dealloc mem, etc */
+       /* XXX need to unregister clocksource, dealloc mem, etc */
        return -EINVAL;
 }
 
+static const struct acpi_device_id hpet_device_ids[] = {
+       {"PNP0103", 0},
+       {"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, hpet_device_ids);
+
 static struct acpi_driver hpet_acpi_driver = {
        .name = "hpet",
-       .ids = "PNP0103",
+       .ids = hpet_device_ids,
        .ops = {
                .add = hpet_acpi_add,
                .remove = hpet_acpi_remove,
@@ -1025,7 +1004,7 @@ static int __init hpet_init(void)
        if (result < 0)
                return -ENODEV;
 
-       sysctl_header = register_sysctl_table(dev_root, 0);
+       sysctl_header = register_sysctl_table(dev_root);
 
        result = acpi_bus_register_driver(&hpet_acpi_driver);
        if (result < 0) {