remove bogus CONFIG_GFAR_NAPI's
[safe/jmp/linux-2.6] / drivers / hwmon / hdaps.c
index eaebfc1..a4d92d2 100644 (file)
@@ -4,11 +4,11 @@
  * Copyright (C) 2005 Robert Love <rml@novell.com>
  * Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com>
  *
- * The HardDisk Active Protection System (hdaps) is present in the IBM ThinkPad
- * T41, T42, T43, R51, and X40, at least.  It provides a basic two-axis
+ * The HardDisk Active Protection System (hdaps) is present in IBM ThinkPads
+ * starting with the R40, T41, and X40.  It provides a basic two-axis
  * accelerometer and other data, such as the device's temperature.
  *
- * Based on the document by Mark A. Smith available at
+ * This driver is based on the document by Mark A. Smith available at
  * http://www.almaden.ibm.com/cs/people/marksmith/tpaps.html and a lot of trial
  * and error.
  *
  */
 
 #include <linux/delay.h>
-#include <linux/device.h>
-#include <linux/input.h>
+#include <linux/platform_device.h>
+#include <linux/input-polldev.h>
 #include <linux/kernel.h>
+#include <linux/mutex.h>
 #include <linux/module.h>
 #include <linux/timer.h>
 #include <linux/dmi.h>
+#include <linux/jiffies.h>
+
 #include <asm/io.h>
 
 #define HDAPS_LOW_PORT         0x1600  /* first port used by hdaps */
-#define HDAPS_NR_PORTS         0x30    /* 0x1600 - 0x162f */
-
-#define STATE_FRESH            0x50    /* accelerometer data is fresh */
-
-#define REFRESH_ASYNC          0x00    /* do asynchronous refresh */
-#define REFRESH_SYNC           0x01    /* do synchronous refresh */
+#define HDAPS_NR_PORTS         0x30    /* number of ports: 0x1600 - 0x162f */
 
 #define HDAPS_PORT_STATE       0x1611  /* device state */
 #define HDAPS_PORT_YPOS                0x1612  /* y-axis position */
 #define        HDAPS_PORT_XPOS         0x1614  /* x-axis position */
-#define HDAPS_PORT_TEMP1       0x1616  /* device temperature, in celcius */
+#define HDAPS_PORT_TEMP1       0x1616  /* device temperature, in Celsius */
 #define HDAPS_PORT_YVAR                0x1617  /* y-axis variance (what is this?) */
 #define HDAPS_PORT_XVAR                0x1619  /* x-axis variance (what is this?) */
 #define HDAPS_PORT_TEMP2       0x161b  /* device temperature (again?) */
 #define HDAPS_PORT_UNKNOWN     0x161c  /* what is this? */
 #define HDAPS_PORT_KMACT       0x161d  /* keyboard or mouse activity */
 
-#define HDAPS_READ_MASK                0xff    /* some reads have the low 8 bits set */
+#define STATE_FRESH            0x50    /* accelerometer data is fresh */
 
 #define KEYBD_MASK             0x20    /* set if keyboard activity */
 #define MOUSE_MASK             0x40    /* set if mouse activity */
 #define INIT_TIMEOUT_MSECS     4000    /* wait up to 4s for device init ... */
 #define INIT_WAIT_MSECS                200     /* ... in 200ms increments */
 
+#define HDAPS_POLL_INTERVAL    50      /* poll for input every 1/20s (50 ms)*/
+#define HDAPS_INPUT_FUZZ       4       /* input event threshold */
+#define HDAPS_INPUT_FLAT       4
+
 static struct platform_device *pdev;
-static struct input_dev hdaps_idev;
-static struct timer_list hdaps_timer;
-static unsigned int hdaps_mousedev_threshold = 4;
-static unsigned long hdaps_poll_ms = 50;
-static unsigned int hdaps_mousedev;
+static struct input_polled_dev *hdaps_idev;
 static unsigned int hdaps_invert;
 static u8 km_activity;
 static int rest_x;
 static int rest_y;
 
-static DECLARE_MUTEX(hdaps_sem);
+static DEFINE_MUTEX(hdaps_mtx);
 
 /*
- * __get_latch - Get the value from a given port.  Callers must hold hdaps_sem.
+ * __get_latch - Get the value from a given port.  Callers must hold hdaps_mtx.
  */
 static inline u8 __get_latch(u16 port)
 {
-       return inb(port) & HDAPS_READ_MASK;
+       return inb(port) & 0xff;
 }
 
 /*
- * __check_latch - Check a port latch for a given value.  Callers must hold
- * hdaps_sem.  Returns zero if the port contains the given value.
+ * __check_latch - Check a port latch for a given value.  Returns zero if the
+ * port contains the given value.  Callers must hold hdaps_mtx.
  */
-static inline unsigned int __check_latch(u16 port, u8 val)
+static inline int __check_latch(u16 port, u8 val)
 {
        if (__get_latch(port) == val)
                return 0;
@@ -97,9 +95,9 @@ static inline unsigned int __check_latch(u16 port, u8 val)
 
 /*
  * __wait_latch - Wait up to 100us for a port latch to get a certain value,
- * returning zero if the value is obtained.  Callers must hold hdaps_sem.
+ * returning zero if the value is obtained.  Callers must hold hdaps_mtx.
  */
-static unsigned int __wait_latch(u16 port, u8 val)
+static int __wait_latch(u16 port, u8 val)
 {
        unsigned int i;
 
@@ -109,59 +107,42 @@ static unsigned int __wait_latch(u16 port, u8 val)
                udelay(5);
        }
 
-       return -EINVAL;
+       return -EIO;
 }
 
 /*
- * __device_refresh - Request a refresh from the accelerometer.
- *
- * If sync is REFRESH_SYNC, we perform a synchronous refresh and will wait.
- * Returns zero if successful and nonzero on error.
- *
- * If sync is REFRESH_ASYNC, we merely kick off a new refresh if the device is
- * not up-to-date.  Always returns zero.
- *
- * Callers must hold hdaps_sem.
+ * __device_refresh - request a refresh from the accelerometer.  Does not wait
+ * for refresh to complete.  Callers must hold hdaps_mtx.
  */
-static int __device_refresh(unsigned int sync)
+static void __device_refresh(void)
 {
-       u8 state;
-
-       udelay(100);
-
-       state = inb(0x1604);
-       if (state == STATE_FRESH)
-               return 0;
-
-       outb(0x11, 0x1610);
-       outb(0x01, 0x161f);
-       if (sync == REFRESH_ASYNC)
-               return 0;
+       udelay(200);
+       if (inb(0x1604) != STATE_FRESH) {
+               outb(0x11, 0x1610);
+               outb(0x01, 0x161f);
+       }
+}
 
+/*
+ * __device_refresh_sync - request a synchronous refresh from the
+ * accelerometer.  We wait for the refresh to complete.  Returns zero if
+ * successful and nonzero on error.  Callers must hold hdaps_mtx.
+ */
+static int __device_refresh_sync(void)
+{
+       __device_refresh();
        return __wait_latch(0x1604, STATE_FRESH);
 }
 
 /*
- * __device_complete - Indicate to the accelerometer that we are done reading
- * data, and then initiate an async refresh.  Callers must hold hdaps_sem.
+ * __device_complete - indicate to the accelerometer that we are done reading
+ * data, and then initiate an async refresh.  Callers must hold hdaps_mtx.
  */
 static inline void __device_complete(void)
 {
        inb(0x161f);
        inb(0x1604);
-       __device_refresh(REFRESH_ASYNC);
-}
-
-static int __hdaps_readb_one(unsigned int port, u8 *val)
-{
-       /* do a sync refresh -- we need to be sure that we read fresh data */
-       if (__device_refresh(REFRESH_SYNC))
-               return -EIO;
-
-       *val = inb(port);
-       __device_complete();
-
-       return 0;
+       __device_refresh();
 }
 
 /*
@@ -173,18 +154,27 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
 {
        int ret;
 
-       down(&hdaps_sem);
-       ret = __hdaps_readb_one(port, val);
-       up(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
+
+       /* do a sync refresh -- we need to be sure that we read fresh data */
+       ret = __device_refresh_sync();
+       if (ret)
+               goto out;
 
+       *val = inb(port);
+       __device_complete();
+
+out:
+       mutex_unlock(&hdaps_mtx);
        return ret;
 }
 
+/* __hdaps_read_pair - internal lockless helper for hdaps_read_pair(). */
 static int __hdaps_read_pair(unsigned int port1, unsigned int port2,
                             int *x, int *y)
 {
        /* do a sync refresh -- we need to be sure that we read fresh data */
-       if (__device_refresh(REFRESH_SYNC))
+       if (__device_refresh_sync())
                return -EIO;
 
        *y = inw(port2);
@@ -210,20 +200,22 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
 {
        int ret;
 
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
        ret = __hdaps_read_pair(port1, port2, val1, val2);
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
 
        return ret;
 }
 
-/* initialize the accelerometer */
+/*
+ * hdaps_device_init - initialize the accelerometer.  Returns zero on success
+ * and negative error code on failure.  Can sleep.
+ */
 static int hdaps_device_init(void)
 {
-       unsigned int total_msecs = INIT_TIMEOUT_MSECS;
-       int ret = -ENXIO;
+       int total, ret = -ENXIO;
 
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
 
        outb(0x13, 0x1610);
        outb(0x01, 0x161f);
@@ -231,8 +223,10 @@ static int hdaps_device_init(void)
                goto out;
 
        /*
-        * The 0x03 value appears to only work on some thinkpads, such as the
-        * T42p.  Others return 0x01.
+        * Most ThinkPads return 0x01.
+        *
+        * Others--namely the R50p, T41p, and T42p--return 0x03.  These laptops
+        * have "inverted" axises.
         *
         * The 0x02 value occurs when the chip has been previously initialized.
         */
@@ -267,150 +261,84 @@ static int hdaps_device_init(void)
        outb(0x01, 0x161f);
        if (__wait_latch(0x161f, 0x00))
                goto out;
-       if (__device_refresh(REFRESH_SYNC))
+       if (__device_refresh_sync())
                goto out;
        if (__wait_latch(0x1611, 0x00))
                goto out;
 
        /* we have done our dance, now let's wait for the applause */
-       while (total_msecs > 0) {
-               u8 ignored;
+       for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
+               int x, y;
 
                /* a read of the device helps push it into action */
-               __hdaps_readb_one(HDAPS_PORT_UNKNOWN, &ignored);
+               __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
                if (!__wait_latch(0x1611, 0x02)) {
                        ret = 0;
                        break;
                }
 
                msleep(INIT_WAIT_MSECS);
-               total_msecs -= INIT_WAIT_MSECS;
        }
 
 out:
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
        return ret;
 }
 
 
-/* Input class stuff */
+/* Device model stuff */
 
-/*
- * hdaps_calibrate - Zero out our "resting" values. Callers must hold hdaps_sem.
- */
-static void hdaps_calibrate(void)
+static int hdaps_probe(struct platform_device *dev)
 {
-       int x, y;
+       int ret;
 
-       if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
-               return;
+       ret = hdaps_device_init();
+       if (ret)
+               return ret;
 
-       rest_x = x;
-       rest_y = y;
+       printk(KERN_INFO "hdaps: device successfully initialized.\n");
+       return 0;
 }
 
-static void hdaps_mousedev_poll(unsigned long unused)
+static int hdaps_resume(struct platform_device *dev)
 {
-       int x, y;
-
-       /* Cannot sleep.  Try nonblockingly.  If we fail, try again later. */
-       if (down_trylock(&hdaps_sem)) {
-               mod_timer(&hdaps_timer,jiffies+msecs_to_jiffies(hdaps_poll_ms));
-               return;
-       }
-
-       if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
-               goto out;
-
-       x -= rest_x;
-       y -= rest_y;
-       if (abs(x) > hdaps_mousedev_threshold)
-               input_report_rel(&hdaps_idev, REL_X, x);
-       if (abs(y) > hdaps_mousedev_threshold)
-               input_report_rel(&hdaps_idev, REL_Y, y);
-       input_sync(&hdaps_idev);
-
-       mod_timer(&hdaps_timer, jiffies + msecs_to_jiffies(hdaps_poll_ms));
-
-out:
-       up(&hdaps_sem);
+       return hdaps_device_init();
 }
 
-/*
- * hdaps_mousedev_enable - enable the input class device.  Can sleep.
- */
-static void hdaps_mousedev_enable(void)
-{
-       down(&hdaps_sem);
-
-       /* calibrate the device before enabling */
-       hdaps_calibrate();
-
-       /* initialize the input class */
-       init_input_dev(&hdaps_idev);
-       hdaps_idev.dev = &pdev->dev;
-       hdaps_idev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
-       hdaps_idev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
-       hdaps_idev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT);
-       input_register_device(&hdaps_idev);
-
-       /* start up our timer */
-       init_timer(&hdaps_timer);
-       hdaps_timer.function = hdaps_mousedev_poll;
-       hdaps_timer.expires = jiffies + msecs_to_jiffies(hdaps_poll_ms);
-       add_timer(&hdaps_timer);
-
-       hdaps_mousedev = 1;
-
-       up(&hdaps_sem);
-
-       printk(KERN_INFO "hdaps: input device enabled.\n");
-}
+static struct platform_driver hdaps_driver = {
+       .probe = hdaps_probe,
+       .resume = hdaps_resume,
+       .driver = {
+               .name = "hdaps",
+               .owner = THIS_MODULE,
+       },
+};
 
 /*
- * hdaps_mousedev_disable - disable the input class device.  Caller must hold
- * hdaps_sem.
+ * hdaps_calibrate - Set our "resting" values.  Callers must hold hdaps_mtx.
  */
-static void hdaps_mousedev_disable(void)
+static void hdaps_calibrate(void)
 {
-       down(&hdaps_sem);
-       if (hdaps_mousedev) {
-               hdaps_mousedev = 0;
-               del_timer_sync(&hdaps_timer);
-               input_unregister_device(&hdaps_idev);
-       }
-       up(&hdaps_sem);
+       __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y);
 }
 
-
-/* Device model stuff */
-
-static int hdaps_probe(struct device *dev)
+static void hdaps_mousedev_poll(struct input_polled_dev *dev)
 {
-       int ret;
+       struct input_dev *input_dev = dev->input;
+       int x, y;
 
-       ret = hdaps_device_init();
-       if (ret)
-               return ret;
+       mutex_lock(&hdaps_mtx);
 
-       printk(KERN_INFO "hdaps: device successfully initialized.\n");
-       return 0;
-}
+       if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
+               goto out;
 
-static int hdaps_resume(struct device *dev, u32 level)
-{
-       if (level == RESUME_ENABLE)
-               return hdaps_device_init();
-       return 0;
-}
+       input_report_abs(input_dev, ABS_X, x - rest_x);
+       input_report_abs(input_dev, ABS_Y, y - rest_y);
+       input_sync(input_dev);
 
-static struct device_driver hdaps_driver = {
-       .name = "hdaps",
-       .bus = &platform_bus_type,
-       .owner = THIS_MODULE,
-       .probe = hdaps_probe,
-       .resume = hdaps_resume
-};
+out:
+       mutex_unlock(&hdaps_mtx);
+}
 
 
 /* Sysfs Files */
@@ -489,9 +417,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
                                     struct device_attribute *attr,
                                     const char *buf, size_t count)
 {
-       down(&hdaps_sem);
+       mutex_lock(&hdaps_mtx);
        hdaps_calibrate();
-       up(&hdaps_sem);
+       mutex_unlock(&hdaps_mtx);
 
        return count;
 }
@@ -517,69 +445,6 @@ static ssize_t hdaps_invert_store(struct device *dev,
        return count;
 }
 
-static ssize_t hdaps_mousedev_show(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
-{
-       return sprintf(buf, "%d\n", hdaps_mousedev);
-}
-
-static ssize_t hdaps_mousedev_store(struct device *dev,
-                                   struct device_attribute *attr,
-                                   const char *buf, size_t count)
-{
-       int enable;
-
-       if (sscanf(buf, "%d", &enable) != 1)
-               return -EINVAL;
-
-       if (enable == 1)
-               hdaps_mousedev_enable();
-       else if (enable == 0)
-               hdaps_mousedev_disable();
-       else
-               return -EINVAL;
-
-       return count;
-}
-
-static ssize_t hdaps_poll_show(struct device *dev,
-                              struct device_attribute *attr, char *buf)
-{
-       return sprintf(buf, "%lu\n", hdaps_poll_ms);
-}
-
-static ssize_t hdaps_poll_store(struct device *dev,
-                               struct device_attribute *attr,
-                               const char *buf, size_t count)
-{
-       unsigned int poll;
-
-       if (sscanf(buf, "%u", &poll) != 1 || poll == 0)
-               return -EINVAL;
-       hdaps_poll_ms = poll;
-
-       return count;
-}
-
-static ssize_t hdaps_threshold_show(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
-{
-       return sprintf(buf, "%u\n", hdaps_mousedev_threshold);
-}
-
-static ssize_t hdaps_threshold_store(struct device *dev,
-                                    struct device_attribute *attr,
-                                    const char *buf, size_t count)
-{
-       unsigned int threshold;
-
-       if (sscanf(buf, "%u", &threshold) != 1 || threshold == 0)
-               return -EINVAL;
-       hdaps_mousedev_threshold = threshold;
-
-       return count;
-}
-
 static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
 static DEVICE_ATTR(variance, 0444, hdaps_variance_show, NULL);
 static DEVICE_ATTR(temp1, 0444, hdaps_temp1_show, NULL);
@@ -588,10 +453,6 @@ static DEVICE_ATTR(keyboard_activity, 0444, hdaps_keyboard_activity_show, NULL);
 static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
 static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
 static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
-static DEVICE_ATTR(mousedev, 0644, hdaps_mousedev_show, hdaps_mousedev_store);
-static DEVICE_ATTR(mousedev_poll_ms, 0644, hdaps_poll_show, hdaps_poll_store);
-static DEVICE_ATTR(mousedev_threshold, 0644, hdaps_threshold_show,
-                  hdaps_threshold_store);
 
 static struct attribute *hdaps_attributes[] = {
        &dev_attr_position.attr,
@@ -601,9 +462,6 @@ static struct attribute *hdaps_attributes[] = {
        &dev_attr_keyboard_activity.attr,
        &dev_attr_mouse_activity.attr,
        &dev_attr_calibrate.attr,
-       &dev_attr_mousedev.attr,
-       &dev_attr_mousedev_threshold.attr,
-       &dev_attr_mousedev_poll_ms.attr,
        &dev_attr_invert.attr,
        NULL,
 };
@@ -615,65 +473,77 @@ static struct attribute_group hdaps_attribute_group = {
 
 /* Module stuff */
 
-/*
- * XXX: We should be able to return nonzero and halt the detection process.
- * But there is a bug in dmi_check_system() where a nonzero return from the
- * first match will result in a return of failure from dmi_check_system().
- * I fixed this; the patch is in 2.6-mm.  Once in Linus's tree we can make
- * hdaps_dmi_match_invert() return hdaps_dmi_match(), which in turn returns 1.
- */
-static int hdaps_dmi_match(struct dmi_system_id *id)
+/* hdaps_dmi_match - found a match.  return one, short-circuiting the hunt. */
+static int __init hdaps_dmi_match(const struct dmi_system_id *id)
 {
        printk(KERN_INFO "hdaps: %s detected.\n", id->ident);
-       return 0;
+       return 1;
 }
 
-static int hdaps_dmi_match_invert(struct dmi_system_id *id)
+/* hdaps_dmi_match_invert - found an inverted match. */
+static int __init hdaps_dmi_match_invert(const struct dmi_system_id *id)
 {
        hdaps_invert = 1;
        printk(KERN_INFO "hdaps: inverting axis readings.\n");
-       return 0;
+       return hdaps_dmi_match(id);
 }
 
-#define HDAPS_DMI_MATCH_NORMAL(model)  {               \
-       .ident = "IBM " model,                          \
+#define HDAPS_DMI_MATCH_NORMAL(vendor, model) {                \
+       .ident = vendor " " model,                      \
        .callback = hdaps_dmi_match,                    \
        .matches = {                                    \
-               DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),     \
+               DMI_MATCH(DMI_BOARD_VENDOR, vendor),    \
                DMI_MATCH(DMI_PRODUCT_VERSION, model)   \
        }                                               \
 }
 
-#define HDAPS_DMI_MATCH_INVERT(model)  {               \
-       .ident = "IBM " model,                          \
+#define HDAPS_DMI_MATCH_INVERT(vendor, model) {                \
+       .ident = vendor " " model,                      \
        .callback = hdaps_dmi_match_invert,             \
        .matches = {                                    \
-               DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),     \
+               DMI_MATCH(DMI_BOARD_VENDOR, vendor),    \
                DMI_MATCH(DMI_PRODUCT_VERSION, model)   \
        }                                               \
 }
 
+/* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match
+   "ThinkPad T42p", so the order of the entries matters.
+   If your ThinkPad is not recognized, please update to latest
+   BIOS. This is especially the case for some R52 ThinkPads. */
+static struct dmi_system_id __initdata hdaps_whitelist[] = {
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad R50p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61i"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61"),
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"),
+       HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61s"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61"),
+       HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61m"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61p"),
+       { .ident = NULL }
+};
+
 static int __init hdaps_init(void)
 {
+       struct input_dev *idev;
        int ret;
 
-       /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */
-       struct dmi_system_id hdaps_whitelist[] = {
-               HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"),
-               HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"),
-               HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
-               HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
-               { .ident = NULL }
-       };
-
        if (!dmi_check_system(hdaps_whitelist)) {
                printk(KERN_WARNING "hdaps: supported laptop not found!\n");
-               ret = -ENXIO;
+               ret = -ENODEV;
                goto out;
        }
 
@@ -682,7 +552,7 @@ static int __init hdaps_init(void)
                goto out;
        }
 
-       ret = driver_register(&hdaps_driver);
+       ret = platform_driver_register(&hdaps_driver);
        if (ret)
                goto out_region;
 
@@ -696,16 +566,45 @@ static int __init hdaps_init(void)
        if (ret)
                goto out_device;
 
-       if (hdaps_mousedev)
-               hdaps_mousedev_enable();
+       hdaps_idev = input_allocate_polled_device();
+       if (!hdaps_idev) {
+               ret = -ENOMEM;
+               goto out_group;
+       }
+
+       hdaps_idev->poll = hdaps_mousedev_poll;
+       hdaps_idev->poll_interval = HDAPS_POLL_INTERVAL;
+
+       /* initial calibrate for the input device */
+       hdaps_calibrate();
+
+       /* initialize the input class */
+       idev = hdaps_idev->input;
+       idev->name = "hdaps";
+       idev->phys = "isa1600/input0";
+       idev->id.bustype = BUS_ISA;
+       idev->dev.parent = &pdev->dev;
+       idev->evbit[0] = BIT_MASK(EV_ABS);
+       input_set_abs_params(idev, ABS_X,
+                       -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
+       input_set_abs_params(idev, ABS_Y,
+                       -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
+
+       ret = input_register_polled_device(hdaps_idev);
+       if (ret)
+               goto out_idev;
 
        printk(KERN_INFO "hdaps: driver successfully loaded.\n");
        return 0;
 
+out_idev:
+       input_free_polled_device(hdaps_idev);
+out_group:
+       sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
 out_device:
        platform_device_unregister(pdev);
 out_driver:
-       driver_unregister(&hdaps_driver);
+       platform_driver_unregister(&hdaps_driver);
 out_region:
        release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
 out:
@@ -715,11 +614,11 @@ out:
 
 static void __exit hdaps_exit(void)
 {
-       hdaps_mousedev_disable();
-
+       input_unregister_polled_device(hdaps_idev);
+       input_free_polled_device(hdaps_idev);
        sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
        platform_device_unregister(pdev);
-       driver_unregister(&hdaps_driver);
+       platform_driver_unregister(&hdaps_driver);
        release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
 
        printk(KERN_INFO "hdaps: driver unloaded.\n");
@@ -728,9 +627,6 @@ static void __exit hdaps_exit(void)
 module_init(hdaps_init);
 module_exit(hdaps_exit);
 
-module_param_named(mousedev, hdaps_mousedev, bool, 0);
-MODULE_PARM_DESC(mousedev, "enable the input class device");
-
 module_param_named(invert, hdaps_invert, bool, 0);
 MODULE_PARM_DESC(invert, "invert data along each axis");