hid: egalax: Correct for device resolution report error
[linux-2.6.git] / drivers / hid / hid-apple.c
index 5642e2c..eaeca56 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/device.h>
 #include <linux/hid.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/usb.h>
 
 #include "hid-ids.h"
@@ -40,6 +41,11 @@ module_param(fnmode, uint, 0644);
 MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
                "[1] = fkeyslast, 2 = fkeysfirst)");
 
+static unsigned int iso_layout = 1;
+module_param(iso_layout, uint, 0644);
+MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
+               "(0 = disabled, [1] = enabled)");
+
 struct apple_sc {
        unsigned long quirks;
        unsigned int fn_on;
@@ -53,12 +59,13 @@ struct apple_key_translation {
        u8 flags;
 };
 
-static struct apple_key_translation apple_fn_keys[] = {
+static const struct apple_key_translation apple_fn_keys[] = {
        { KEY_BACKSPACE, KEY_DELETE },
+       { KEY_ENTER,    KEY_INSERT },
        { KEY_F1,       KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
        { KEY_F2,       KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
-       { KEY_F3,       KEY_FN_F5,          APPLE_FLAG_FKEY }, /* Exposé */
-       { KEY_F4,       KEY_FN_F4,          APPLE_FLAG_FKEY }, /* Dashboard */
+       { KEY_F3,       KEY_SCALE,          APPLE_FLAG_FKEY },
+       { KEY_F4,       KEY_DASHBOARD,      APPLE_FLAG_FKEY },
        { KEY_F5,       KEY_KBDILLUMDOWN,   APPLE_FLAG_FKEY },
        { KEY_F6,       KEY_KBDILLUMUP,     APPLE_FLAG_FKEY },
        { KEY_F7,       KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
@@ -74,7 +81,7 @@ static struct apple_key_translation apple_fn_keys[] = {
        { }
 };
 
-static struct apple_key_translation powerbook_fn_keys[] = {
+static const struct apple_key_translation powerbook_fn_keys[] = {
        { KEY_BACKSPACE, KEY_DELETE },
        { KEY_F1,       KEY_BRIGHTNESSDOWN,     APPLE_FLAG_FKEY },
        { KEY_F2,       KEY_BRIGHTNESSUP,       APPLE_FLAG_FKEY },
@@ -93,7 +100,7 @@ static struct apple_key_translation powerbook_fn_keys[] = {
        { }
 };
 
-static struct apple_key_translation powerbook_numlock_keys[] = {
+static const struct apple_key_translation powerbook_numlock_keys[] = {
        { KEY_J,        KEY_KP1 },
        { KEY_K,        KEY_KP2 },
        { KEY_L,        KEY_KP3 },
@@ -116,16 +123,16 @@ static struct apple_key_translation powerbook_numlock_keys[] = {
        { }
 };
 
-static struct apple_key_translation apple_iso_keyboard[] = {
+static const struct apple_key_translation apple_iso_keyboard[] = {
        { KEY_GRAVE,    KEY_102ND },
        { KEY_102ND,    KEY_GRAVE },
        { }
 };
 
-static struct apple_key_translation *apple_find_translation(
-               struct apple_key_translation *table, u16 from)
+static const struct apple_key_translation *apple_find_translation(
+               const struct apple_key_translation *table, u16 from)
 {
-       struct apple_key_translation *trans;
+       const struct apple_key_translation *trans;
 
        /* Look for the translation */
        for (trans = table; trans->from; trans++)
@@ -139,7 +146,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
                struct hid_usage *usage, __s32 value)
 {
        struct apple_sc *asc = hid_get_drvdata(hid);
-       struct apple_key_translation *trans;
+       const struct apple_key_translation *trans;
 
        if (usage->code == KEY_FN) {
                asc->fn_on = !!value;
@@ -150,7 +157,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
        if (fnmode) {
                int do_translate;
 
-               trans = apple_find_translation((hid->product < 0x220 ||
+               trans = apple_find_translation((hid->product < 0x21d ||
                                        hid->product >= 0x300) ?
                                        powerbook_fn_keys : apple_fn_keys,
                                        usage->code);
@@ -198,11 +205,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
                }
        }
 
-       if (asc->quirks & APPLE_ISO_KEYBOARD) {
-               trans = apple_find_translation(apple_iso_keyboard, usage->code);
-               if (trans) {
-                       input_event(input, usage->type, trans->to, value);
-                       return 1;
+        if (iso_layout) {
+               if (asc->quirks & APPLE_ISO_KEYBOARD) {
+                       trans = apple_find_translation(apple_iso_keyboard, usage->code);
+                       if (trans) {
+                               input_event(input, usage->type, trans->to, value);
+                               return 1;
+                       }
                }
        }
 
@@ -237,22 +246,23 @@ static int apple_event(struct hid_device *hdev, struct hid_field *field,
 /*
  * MacBook JIS keyboard has wrong logical maximum
  */
-static void apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
-               unsigned int rsize)
+static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int *rsize)
 {
        struct apple_sc *asc = hid_get_drvdata(hdev);
 
-       if ((asc->quirks & APPLE_RDESC_JIS) && rsize >= 60 &&
+       if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
                        rdesc[53] == 0x65 && rdesc[59] == 0x65) {
                dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report "
                                "descriptor\n");
                rdesc[53] = rdesc[59] = 0xe7;
        }
+       return rdesc;
 }
 
 static void apple_setup_input(struct input_dev *input)
 {
-       struct apple_key_translation *trans;
+       const struct apple_key_translation *trans;
 
        set_bit(KEY_NUMLOCK, input->keybit);
 
@@ -309,15 +319,9 @@ static int apple_probe(struct hid_device *hdev,
 {
        unsigned long quirks = id->driver_data;
        struct apple_sc *asc;
+       unsigned int connect_mask = HID_CONNECT_DEFAULT;
        int ret;
 
-       /* return something else or move to hid layer? device will reside
-          allocated */
-       if (id->bus == BUS_USB && (quirks & APPLE_IGNORE_MOUSE) &&
-                       to_usb_interface(hdev->dev.parent)->cur_altsetting->
-                       desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
-               return -ENODEV;
-
        asc = kzalloc(sizeof(*asc), GFP_KERNEL);
        if (asc == NULL) {
                dev_err(&hdev->dev, "can't alloc apple descriptor\n");
@@ -328,18 +332,18 @@ static int apple_probe(struct hid_device *hdev,
 
        hid_set_drvdata(hdev, asc);
 
-       if (quirks & APPLE_HIDDEV)
-               hdev->quirks |= HID_QUIRK_HIDDEV;
-       if (quirks & APPLE_IGNORE_HIDINPUT)
-               hdev->quirks |= HID_QUIRK_IGNORE_HIDINPUT;
-
        ret = hid_parse(hdev);
        if (ret) {
                dev_err(&hdev->dev, "parse failed\n");
                goto err_free;
        }
 
-       ret = hid_hw_start(hdev);
+       if (quirks & APPLE_HIDDEV)
+               connect_mask |= HID_CONNECT_HIDDEV_FORCE;
+       if (quirks & APPLE_IGNORE_HIDINPUT)
+               connect_mask &= ~HID_CONNECT_HIDINPUT;
+
+       ret = hid_hw_start(hdev, connect_mask);
        if (ret) {
                dev_err(&hdev->dev, "hw start failed\n");
                goto err_free;
@@ -358,44 +362,46 @@ static void apple_remove(struct hid_device *hdev)
 }
 
 static const struct hid_device_id apple_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL),
+               .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4),
                .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
                .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
 
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
+                       APPLE_ISO_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
+                       APPLE_ISO_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+                       APPLE_RDESC_JIS },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
+                       APPLE_ISO_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS},
+                       APPLE_RDESC_JIS },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
+               .driver_data = APPLE_HAS_FN },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
+               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
+               .driver_data = APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
                .driver_data = APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
@@ -403,45 +409,48 @@ static const struct hid_device_id apple_devices[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
                .driver_data = APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
-       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
+                       APPLE_RDESC_JIS },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
-       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
                        APPLE_ISO_KEYBOARD },
-       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
-               .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
-               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
-               .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
-               .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
-               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD |
-                       APPLE_IGNORE_MOUSE },
+               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
-               .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
-       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
+               .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
+               .driver_data = APPLE_HAS_FN },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
+               .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
+               .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
                .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
+                       APPLE_ISO_KEYBOARD },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
+       { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
-               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
-                       APPLE_IGNORE_MOUSE },
-
-       /* Apple wireless Mighty Mouse */
-       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c),
-               .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
+               .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
 
        { }
 };
@@ -458,7 +467,7 @@ static struct hid_driver apple_driver = {
        .input_mapped = apple_input_mapped,
 };
 
-static int apple_init(void)
+static int __init apple_init(void)
 {
        int ret;
 
@@ -469,7 +478,7 @@ static int apple_init(void)
        return ret;
 }
 
-static void apple_exit(void)
+static void __exit apple_exit(void)
 {
        hid_unregister_driver(&apple_driver);
 }