#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>
static u32 hpet_ntimer, hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
/* A lock for concurrent access by app and isr hpet activity. */
-static spinlock_t hpet_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(hpet_lock);
/* A lock for concurrent intermodule access to hpet and isr hpet activity. */
-static spinlock_t hpet_task_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(hpet_task_lock);
#define HPET_DEV_NAME (7)
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;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
addr = __pa(addr);
- 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");
+ 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");
return -EAGAIN;
}
return hpet_ioctl_common(devp, cmd, arg, 1);
}
-#ifdef CONFIG_TIME_INTERPOLATION
-
-static struct time_interpolator hpet_interpolator = {
- .source = TIME_SOURCE_MMIO64,
- .shift = 10
-};
-
-#endif
-
static ctl_table hpet_table[] = {
{
.ctl_name = 1,
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
*/
#define TICK_CALIBRATE (1000UL)
-static unsigned long __init 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;
return (m - start) / i;
}
-int __init hpet_alloc(struct hpet_data *hdp)
+int hpet_alloc(struct hpet_data *hdp)
{
u64 cap, mcfg;
struct hpet_dev *devp;
struct hpets *hpetp;
size_t siz;
struct hpet __iomem *hpet;
- static struct hpets *last __initdata = (struct hpets *)0;
+ static struct hpets *last = (struct hpets *)0;
unsigned long ns;
/*
hpetp->hp_period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >>
HPET_COUNTER_CLK_PERIOD_SHIFT;
- printk(KERN_INFO "hpet%d: at MMIO 0x%p, IRQ%s",
- hpetp->hp_which, hpet, hpetp->hp_ntimer > 1 ? "s" : "");
+ 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");
}
hpetp->hp_delta = hpet_calibrate(hpetp);
+ hpet_register_interpolator(hpetp);
return 0;
}
-static acpi_status __init hpet_resources(struct acpi_resource *res, void *data)
+static acpi_status hpet_resources(struct acpi_resource *res, void *data)
{
struct hpet_data *hdp;
acpi_status 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);
for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
return AE_OK;
}
-static int __init hpet_acpi_add(struct acpi_device *device)
+static int hpet_acpi_add(struct acpi_device *device)
{
acpi_status result;
struct hpet_data data;
return hpet_alloc(&data);
}
-static int __init hpet_acpi_remove(struct acpi_device *device, int type)
+static int hpet_acpi_remove(struct acpi_device *device, int type)
{
- return 0;
+ /* XXX need to unregister interpolator, dealloc mem, etc */
+ return -EINVAL;
}
static struct acpi_driver hpet_acpi_driver = {
static int __init hpet_init(void)
{
- (void)acpi_bus_register_driver(&hpet_acpi_driver);
+ int result;
- if (hpets) {
- if (misc_register(&hpet_misc))
- return -ENODEV;
+ result = misc_register(&hpet_misc);
+ if (result < 0)
+ return -ENODEV;
- sysctl_header = register_sysctl_table(dev_root, 0);
+ sysctl_header = register_sysctl_table(dev_root, 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;
+ 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;
+ }
+
+ return 0;
}
static void __exit hpet_exit(void)
{
acpi_bus_unregister_driver(&hpet_acpi_driver);
- if (hpets)
+ if (sysctl_header)
unregister_sysctl_table(sysctl_header);
+ misc_deregister(&hpet_misc);
return;
}