This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / char / hpet.c
index ca7d88a..75d8b7b 100644 (file)
 #include <linux/wait.h>
 #include <linux/bcd.h>
 #include <linux/seq_file.h>
-#include <linux/bitops.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/bitops.h>
 #include <asm/div64.h>
 
 #include <linux/acpi.h>
@@ -76,7 +76,6 @@ struct hpet_dev {
 struct hpets {
        struct hpets *hp_next;
        struct hpet __iomem *hp_hpet;
-       struct time_interpolator *hp_interpolator;
        unsigned long hp_period;
        unsigned long hp_delta;
        unsigned int hp_ntimer;
@@ -274,9 +273,9 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
        addr = __pa(addr);
 
-       if (remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
-                                       PAGE_SIZE, vma->vm_page_prot)) {
-               printk(KERN_ERR "remap_pfn_range failed in hpet.c\n");
+       if (remap_page_range
+           (vma, vma->vm_start, addr, PAGE_SIZE, vma->vm_page_prot)) {
+               printk(KERN_ERR "remap_page_range failed in hpet.c\n");
                return -EAGAIN;
        }
 
@@ -661,6 +660,16 @@ int hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg)
        return hpet_ioctl_common(devp, cmd, arg, 1);
 }
 
+#ifdef CONFIG_TIME_INTERPOLATION
+
+static struct time_interpolator hpet_interpolator = {
+       .source = TIME_SOURCE_MMIO64,
+       .shift = 10,
+       .mask = 0xffffffffffffffffLL
+};
+
+#endif
+
 static ctl_table hpet_table[] = {
        {
         .ctl_name = 1,
@@ -697,28 +706,6 @@ static ctl_table dev_root[] = {
 
 static struct ctl_table_header *sysctl_header;
 
-static void hpet_register_interpolator(struct hpets *hpetp)
-{
-#ifdef CONFIG_TIME_INTERPOLATION
-       struct time_interpolator *ti;
-
-       ti = kmalloc(sizeof(*ti), GFP_KERNEL);
-       if (!ti)
-               return;
-
-       memset(ti, 0, sizeof(*ti));
-       ti->source = TIME_SOURCE_MMIO64;
-       ti->shift = 10;
-       ti->addr = &hpetp->hp_hpet->hpet_mc;
-       ti->frequency = hpet_time_div(hpets->hp_period);
-       ti->drift = ti->frequency * HPET_DRIFT / 1000000;
-       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
@@ -726,7 +713,7 @@ static void hpet_register_interpolator(struct hpets *hpetp)
  */
 #define        TICK_CALIBRATE  (1000UL)
 
-static unsigned long hpet_calibrate(struct hpets *hpetp)
+static unsigned long __init hpet_calibrate(struct hpets *hpetp)
 {
        struct hpet_timer __iomem *timer = NULL;
        unsigned long t, m, count, i, flags, start;
@@ -763,7 +750,7 @@ static unsigned long hpet_calibrate(struct hpets *hpetp)
        return (m - start) / i;
 }
 
-int hpet_alloc(struct hpet_data *hdp)
+int __init hpet_alloc(struct hpet_data *hdp)
 {
        u64 cap, mcfg;
        struct hpet_dev *devp;
@@ -771,7 +758,7 @@ int hpet_alloc(struct hpet_data *hdp)
        struct hpets *hpetp;
        size_t siz;
        struct hpet __iomem *hpet;
-       static struct hpets *last = (struct hpets *)0;
+       static struct hpets *last __initdata = (struct hpets *)0;
        unsigned long ns;
 
        /*
@@ -824,9 +811,8 @@ int hpet_alloc(struct hpet_data *hdp)
        hpetp->hp_period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >>
            HPET_COUNTER_CLK_PERIOD_SHIFT;
 
-       printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s",
-               hpetp->hp_which, hdp->hd_phys_address,
-               hpetp->hp_ntimer > 1 ? "s" : "");
+       printk(KERN_INFO "hpet%d: at MMIO 0x%p, IRQ%s",
+               hpetp->hp_which, hpet, hpetp->hp_ntimer > 1 ? "s" : "");
        for (i = 0; i < hpetp->hp_ntimer; i++)
                printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
        printk("\n");
@@ -869,12 +855,11 @@ int hpet_alloc(struct hpet_data *hdp)
        }
 
        hpetp->hp_delta = hpet_calibrate(hpetp);
-       hpet_register_interpolator(hpetp);
 
        return 0;
 }
 
-static acpi_status hpet_resources(struct acpi_resource *res, void *data)
+static acpi_status __init hpet_resources(struct acpi_resource *res, void *data)
 {
        struct hpet_data *hdp;
        acpi_status status;
@@ -889,7 +874,6 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
                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);
 
                for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
@@ -915,7 +899,7 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
        return AE_OK;
 }
 
-static int hpet_acpi_add(struct acpi_device *device)
+static int __init hpet_acpi_add(struct acpi_device *device)
 {
        acpi_status result;
        struct hpet_data data;
@@ -937,10 +921,9 @@ static int hpet_acpi_add(struct acpi_device *device)
        return hpet_alloc(&data);
 }
 
-static int hpet_acpi_remove(struct acpi_device *device, int type)
+static int __init hpet_acpi_remove(struct acpi_device *device, int type)
 {
-       /* XXX need to unregister interpolator, dealloc mem, etc */
-       return -EINVAL;
+       return 0;
 }
 
 static struct acpi_driver hpet_acpi_driver = {
@@ -956,32 +939,37 @@ static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
 
 static int __init hpet_init(void)
 {
-       int result;
-
-       result = misc_register(&hpet_misc);
-       if (result < 0)
-               return -ENODEV;
+       (void)acpi_bus_register_driver(&hpet_acpi_driver);
 
-       sysctl_header = register_sysctl_table(dev_root, 0);
+       if (hpets) {
+               if (misc_register(&hpet_misc))
+                       return -ENODEV;
 
-       result = acpi_bus_register_driver(&hpet_acpi_driver);
-       if (result < 0) {
-               if (sysctl_header)
-                       unregister_sysctl_table(sysctl_header);
-               misc_deregister(&hpet_misc);
-               return result;
-       }
+               sysctl_header = register_sysctl_table(dev_root, 0);
 
-       return 0;
+#ifdef CONFIG_TIME_INTERPOLATION
+               {
+                       struct hpet *hpet;
+
+                       hpet = hpets->hp_hpet;
+                       hpet_interpolator.addr = &hpets->hp_hpet->hpet_mc;
+                       hpet_interpolator.frequency = hpet_time_div(hpets->hp_period);
+                       hpet_interpolator.drift = hpet_interpolator.frequency *
+                           HPET_DRIFT / 1000000;
+                       register_time_interpolator(&hpet_interpolator);
+               }
+#endif
+               return 0;
+       } else
+               return -ENODEV;
 }
 
 static void __exit hpet_exit(void)
 {
        acpi_bus_unregister_driver(&hpet_acpi_driver);
 
-       if (sysctl_header)
+       if (hpets)
                unregister_sysctl_table(sysctl_header);
-       misc_deregister(&hpet_misc);
 
        return;
 }