include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / input / mouse / lifebook.c
index 91109b4..c31ad11 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/serio.h>
 #include <linux/libps2.h>
 #include <linux/dmi.h>
+#include <linux/slab.h>
 
 #include "psmouse.h"
 #include "lifebook.h"
@@ -25,63 +26,76 @@ struct lifebook_data {
        char phys[32];
 };
 
+static bool lifebook_present;
+
 static const char *desired_serio_phys;
 
-static int lifebook_set_serio_phys(struct dmi_system_id *d)
+static int lifebook_limit_serio3(const struct dmi_system_id *d)
 {
-       desired_serio_phys = d->driver_data;
+       desired_serio_phys = "isa0060/serio3";
        return 0;
 }
 
-static unsigned char lifebook_use_6byte_proto;
+static bool lifebook_use_6byte_proto;
 
-static int lifebook_set_6byte_proto(struct dmi_system_id *d)
+static int lifebook_set_6byte_proto(const struct dmi_system_id *d)
 {
-       lifebook_use_6byte_proto = 1;
+       lifebook_use_6byte_proto = true;
        return 0;
 }
 
-static struct dmi_system_id lifebook_dmi_table[] = {
+static const struct dmi_system_id __initconst lifebook_dmi_table[] = {
        {
-               .ident = "FLORA-ie 55mi",
+               /* FLORA-ie 55mi */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
                },
        },
        {
-               .ident = "LifeBook B",
+               /* LifeBook B */
+               .matches = {
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Lifebook B Series"),
+               },
+       },
+       {
+               /* LifeBook B */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
                },
        },
        {
-               .ident = "Lifebook B",
+               /* Lifebook B */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
                },
        },
        {
-               .ident = "Lifebook B213x/B2150",
+               /* Lifebook B-2130 */
+               .matches = {
+                       DMI_MATCH(DMI_BOARD_NAME, "ZEPHYR"),
+               },
+       },
+       {
+               /* Lifebook B213x/B2150 */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
                },
        },
        {
-               .ident = "Zephyr",
+               /* Zephyr */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
                },
        },
        {
-               .ident = "CF-18",
+               /* Panasonic CF-18 */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
                },
-               .callback = lifebook_set_serio_phys,
-               .driver_data = "isa0060/serio3",
+               .callback = lifebook_limit_serio3,
        },
        {
-               .ident = "Panasonic CF-28",
+               /* Panasonic CF-28 */
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
@@ -89,7 +103,7 @@ static struct dmi_system_id lifebook_dmi_table[] = {
                .callback = lifebook_set_6byte_proto,
        },
        {
-               .ident = "Panasonic CF-29",
+               /* Panasonic CF-29 */
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
@@ -97,7 +111,14 @@ static struct dmi_system_id lifebook_dmi_table[] = {
                .callback = lifebook_set_6byte_proto,
        },
        {
-               .ident = "Lifebook B142",
+               /* Panasonic CF-72 */
+               .matches = {
+                       DMI_MATCH(DMI_PRODUCT_NAME, "CF-72"),
+               },
+               .callback = lifebook_set_6byte_proto,
+       },
+       {
+               /* Lifebook B142 */
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
                },
@@ -105,13 +126,18 @@ static struct dmi_system_id lifebook_dmi_table[] = {
        { }
 };
 
+void __init lifebook_module_init(void)
+{
+       lifebook_present = dmi_check_system(lifebook_dmi_table);
+}
+
 static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
 {
        struct lifebook_data *priv = psmouse->private;
        struct input_dev *dev1 = psmouse->dev;
        struct input_dev *dev2 = priv ? priv->dev2 : NULL;
        unsigned char *packet = psmouse->packet;
-       int relative_packet = packet[0] & 0x08;
+       bool relative_packet = packet[0] & 0x08;
 
        if (relative_packet || !lifebook_use_6byte_proto) {
                if (psmouse->pktcnt != 3)
@@ -145,21 +171,22 @@ static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
                if (!dev2)
                        printk(KERN_WARNING "lifebook.c: got relative packet "
                                "but no relative device set up\n");
-       } else if (lifebook_use_6byte_proto) {
-               input_report_abs(dev1, ABS_X,
-                                ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
-               input_report_abs(dev1, ABS_Y,
-                                4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
        } else {
-               input_report_abs(dev1, ABS_X,
-                                (packet[1] | ((packet[0] & 0x30) << 4)));
-               input_report_abs(dev1, ABS_Y,
-                                1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
+               if (lifebook_use_6byte_proto) {
+                       input_report_abs(dev1, ABS_X,
+                               ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
+                       input_report_abs(dev1, ABS_Y,
+                               4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
+               } else {
+                       input_report_abs(dev1, ABS_X,
+                               (packet[1] | ((packet[0] & 0x30) << 4)));
+                       input_report_abs(dev1, ABS_Y,
+                               1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
+               }
+               input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
+               input_sync(dev1);
        }
 
-       input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
-       input_sync(dev1);
-
        if (dev2) {
                if (relative_packet) {
                        input_report_rel(dev2, REL_X,
@@ -184,10 +211,10 @@ static int lifebook_absolute_mode(struct psmouse *psmouse)
                return -1;
 
        /*
-          Enable absolute output -- ps2_command fails always but if
-          you leave this call out the touchsreen will never send
-          absolute coordinates
-       */
+        * Enable absolute output -- ps2_command fails always but if
+        * you leave this call out the touchsreen will never send
+        * absolute coordinates
+        */
        param = lifebook_use_6byte_proto ? 0x08 : 0x07;
        ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
 
@@ -217,14 +244,19 @@ static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolu
 
 static void lifebook_disconnect(struct psmouse *psmouse)
 {
+       struct lifebook_data *priv = psmouse->private;
+
        psmouse_reset(psmouse);
-       kfree(psmouse->private);
+       if (priv) {
+               input_unregister_device(priv->dev2);
+               kfree(priv);
+       }
        psmouse->private = NULL;
 }
 
-int lifebook_detect(struct psmouse *psmouse, int set_properties)
+int lifebook_detect(struct psmouse *psmouse, bool set_properties)
 {
-        if (!dmi_check_system(lifebook_dmi_table))
+        if (!lifebook_present)
                 return -1;
 
        if (desired_serio_phys &&
@@ -262,9 +294,10 @@ static int lifebook_create_relative_device(struct psmouse *psmouse)
        dev2->id.version = 0x0000;
        dev2->dev.parent = &psmouse->ps2dev.serio->dev;
 
-       dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
-       dev2->relbit[LONG(REL_X)] = BIT(REL_X) | BIT(REL_Y);
-       dev2->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
+       dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
+       dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
+       dev2->keybit[BIT_WORD(BTN_LEFT)] =
+                               BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
 
        error = input_register_device(priv->dev2);
        if (error)
@@ -282,14 +315,15 @@ static int lifebook_create_relative_device(struct psmouse *psmouse)
 int lifebook_init(struct psmouse *psmouse)
 {
        struct input_dev *dev1 = psmouse->dev;
-       int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
+       int max_coord = lifebook_use_6byte_proto ? 4096 : 1024;
 
        if (lifebook_absolute_mode(psmouse))
                return -1;
 
-       dev1->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
+       dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
        dev1->relbit[0] = 0;
-       dev1->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
+       dev1->keybit[BIT_WORD(BTN_MOUSE)] = 0;
+       dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
        input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
        input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);