Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[safe/jmp/linux-2.6] / drivers / hid / hid-input.c
index f1df25a..7a0d2e4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (c) 2000-2001 Vojtech Pavlik
- *  Copyright (c) 2006-2007 Jiri Kosina
+ *  Copyright (c) 2006-2010 Jiri Kosina
  *
  *  HID to Linux Input mapping
  */
@@ -68,22 +68,25 @@ static const struct {
 #define map_key_clear(c)       hid_map_usage_clear(hidinput, usage, &bit, \
                &max, EV_KEY, (c))
 
-static inline int match_scancode(int code, int scancode)
+static inline int match_scancode(unsigned int code, unsigned int scancode)
 {
        if (scancode == 0)
                return 1;
-       return ((code & (HID_USAGE_PAGE | HID_USAGE)) == scancode);
+
+       return (code & (HID_USAGE_PAGE | HID_USAGE)) == scancode;
 }
 
-static inline int match_keycode(int code, int keycode)
+static inline int match_keycode(unsigned int code, unsigned int keycode)
 {
        if (keycode == 0)
                return 1;
-       return (code == keycode);
+
+       return code == keycode;
 }
 
 static struct hid_usage *hidinput_find_key(struct hid_device *hid,
-               int scancode, int keycode)
+                                          unsigned int scancode,
+                                          unsigned int keycode)
 {
        int i, j, k;
        struct hid_report *report;
@@ -105,8 +108,8 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid,
        return NULL;
 }
 
-static int hidinput_getkeycode(struct input_dev *dev, int scancode,
-                               int *keycode)
+static int hidinput_getkeycode(struct input_dev *dev,
+                              unsigned int scancode, unsigned int *keycode)
 {
        struct hid_device *hid = input_get_drvdata(dev);
        struct hid_usage *usage;
@@ -119,16 +122,13 @@ static int hidinput_getkeycode(struct input_dev *dev, int scancode,
        return -EINVAL;
 }
 
-static int hidinput_setkeycode(struct input_dev *dev, int scancode,
-                               int keycode)
+static int hidinput_setkeycode(struct input_dev *dev,
+                              unsigned int scancode, unsigned int keycode)
 {
        struct hid_device *hid = input_get_drvdata(dev);
        struct hid_usage *usage;
        int old_keycode;
 
-       if (keycode < 0 || keycode > KEY_MAX)
-               return -EINVAL;
-
        usage = hidinput_find_key(hid, scancode, 0);
        if (usage) {
                old_keycode = usage->code;
@@ -154,30 +154,20 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
 {
        struct input_dev *input = hidinput->input;
        struct hid_device *device = input_get_drvdata(input);
-       int max = 0, code, ret;
+       int max = 0, code;
        unsigned long *bit = NULL;
 
        field->hidinput = hidinput;
 
-       dbg_hid("Mapping: ");
-       hid_resolv_usage(usage->hid);
-       dbg_hid_line(" ---> ");
-
        if (field->flags & HID_MAIN_ITEM_CONSTANT)
                goto ignore;
 
        /* only LED usages are supported in output fields */
        if (field->report_type == HID_OUTPUT_REPORT &&
                        (usage->hid & HID_USAGE_PAGE) != HID_UP_LED) {
-               dbg_hid_line(" [non-LED output field] ");
                goto ignore;
        }
 
-       /* handle input mappings for quirky devices */
-       ret = hidinput_mapping_quirks(usage, hidinput, &bit, &max);
-       if (ret)
-               goto mapped;
-
        if (device->driver->input_mapping) {
                int ret = device->driver->input_mapping(device, hidinput, field,
                                usage, &bit, &max);
@@ -203,12 +193,17 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
                break;
 
        case HID_UP_BUTTON:
-               code = ((usage->hid - 1) & 0xf);
+               code = ((usage->hid - 1) & HID_USAGE);
 
                switch (field->application) {
                case HID_GD_MOUSE:
                case HID_GD_POINTER:  code += 0x110; break;
-               case HID_GD_JOYSTICK: code += 0x120; break;
+               case HID_GD_JOYSTICK:
+                                     if (code <= 0xf)
+                                             code += BTN_JOYSTICK;
+                                     else
+                                             code += BTN_TRIGGER_HAPPY;
+                                     break;
                case HID_GD_GAMEPAD:  code += 0x130; break;
                default:
                        switch (field->physical) {
@@ -410,6 +405,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
                case 0x192: map_key_clear(KEY_CALC);            break;
                case 0x194: map_key_clear(KEY_FILE);            break;
                case 0x196: map_key_clear(KEY_WWW);             break;
+               case 0x199: map_key_clear(KEY_CHAT);            break;
                case 0x19c: map_key_clear(KEY_LOGOFF);          break;
                case 0x19e: map_key_clear(KEY_COFFEE);          break;
                case 0x1a6: map_key_clear(KEY_HELP);            break;
@@ -515,15 +511,6 @@ mapped:
                                hidinput, field, usage, &bit, &max) < 0)
                goto ignore;
 
-       if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 |
-                       HID_QUIRK_2WHEEL_MOUSE_HACK_B8)) && (usage->type == EV_REL) &&
-                       (usage->code == REL_WHEEL))
-               set_bit(REL_HWHEEL, bit);
-
-       if ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) &&
-                       (usage->hid == 0x00090007))
-               goto ignore;
-
        set_bit(usage->type, input->evbit);
 
        while (usage->code <= max && test_and_set_bit(usage->code, bit))
@@ -575,15 +562,9 @@ mapped:
                set_bit(MSC_SCAN, input->mscbit);
        }
 
-       hid_resolv_event(usage->type, usage->code);
-
-       dbg_hid_line("\n");
-
-       return;
-
 ignore:
-       dbg_hid_line("IGNORED\n");
        return;
+
 }
 
 void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
@@ -599,10 +580,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
        if (!usage->type)
                return;
 
-       /* handle input events for quirky devices */
-       if (hidinput_event_quirks(hid, field, usage, value))
-               return;
-
        if (usage->hat_min < usage->hat_max || usage->hat_dir) {
                int hat_dir = usage->hat_dir;
                if (!hat_dir)
@@ -718,7 +695,7 @@ static void hidinput_close(struct input_dev *dev)
  * Read all reports and initialize the absolute field values.
  */
 
-int hidinput_connect(struct hid_device *hid)
+int hidinput_connect(struct hid_device *hid, unsigned int force)
 {
        struct hid_report *report;
        struct hid_input *hidinput = NULL;
@@ -726,19 +703,20 @@ int hidinput_connect(struct hid_device *hid)
        int i, j, k;
        int max_report_type = HID_OUTPUT_REPORT;
 
-       if (hid->quirks & HID_QUIRK_IGNORE_HIDINPUT)
-               return -1;
-
        INIT_LIST_HEAD(&hid->inputs);
 
-       for (i = 0; i < hid->maxcollection; i++)
-               if (hid->collection[i].type == HID_COLLECTION_APPLICATION ||
-                   hid->collection[i].type == HID_COLLECTION_PHYSICAL)
-                       if (IS_INPUT_APPLICATION(hid->collection[i].usage))
-                               break;
+       if (!force) {
+               for (i = 0; i < hid->maxcollection; i++) {
+                       struct hid_collection *col = &hid->collection[i];
+                       if (col->type == HID_COLLECTION_APPLICATION ||
+                                       col->type == HID_COLLECTION_PHYSICAL)
+                               if (IS_INPUT_APPLICATION(col->usage))
+                                       break;
+               }
 
-       if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDINPUT) == 0)
-               return -1;
+               if (i == hid->maxcollection)
+                       return -1;
+       }
 
        if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS)
                max_report_type = HID_INPUT_REPORT;