]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
HID: move cypress quirks
authorJiri Slaby <jirislaby@gmail.com>
Mon, 23 Jun 2008 20:54:08 +0000 (22:54 +0200)
committerJiri Kosina <jkosina@suse.cz>
Tue, 14 Oct 2008 21:50:51 +0000 (23:50 +0200)
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/Kconfig
drivers/hid/Makefile
drivers/hid/hid-core.c
drivers/hid/hid-cypress.c [new file with mode: 0644]
drivers/hid/hid-dummy.c
drivers/hid/hid-input-quirks.c
drivers/hid/hid-input.c
drivers/hid/usbhid/hid-quirks.c
include/linux/hid.h

index 147223993b86895ce9258f1d733eeccf1ccf1c29..69f3420882a62fe7640bc1527cd54a4bd4094ed6 100644 (file)
@@ -96,6 +96,13 @@ config HID_APPLE
 
        If unsure, say M.
 
+config HID_CYPRESS
+       tristate "Cypress"
+       default m
+       depends on USB_HID
+       ---help---
+       Support for Cypress mouse and barcodes.
+
 config HID_LOGITECH
        tristate "Logitech"
        default m
index 314d5b0c70d5b6f785d02ec8f3f808f74f55e8f9..061066201186f9f26aa0cbb7fa9d68d18b0bb0ef 100644 (file)
@@ -13,6 +13,7 @@ obj-m                         += hid-dummy.o
 endif
 
 obj-$(CONFIG_HID_APPLE)                += hid-apple.o
+obj-$(CONFIG_HID_CYPRESS)      += hid-cypress.o
 obj-$(CONFIG_HID_LOGITECH)     += hid-logitech.o
 obj-$(CONFIG_HID_MICROSOFT)    += hid-microsoft.o
 obj-$(CONFIG_HID_SUNPLUS)      += hid-sunplus.o
index e9e6dbbaaa83eee597eac687690c74207a7734c9..331670b32e6801e5446ef4f207db9637b8c97564 100644 (file)
@@ -1162,6 +1162,9 @@ static const struct hid_device_id hid_blacklist[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c
new file mode 100644 (file)
index 0000000..a1e13f1
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ *  HID driver for some cypress "special" devices
+ *
+ *  Copyright (c) 1999 Andreas Gal
+ *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
+ *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
+ *  Copyright (c) 2006-2007 Jiri Kosina
+ *  Copyright (c) 2007 Paul Walmsley
+ *  Copyright (c) 2008 Jiri Slaby
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/input.h>
+#include <linux/module.h>
+
+#include "hid-ids.h"
+
+#define CP_RDESC_SWAPPED_MIN_MAX       0x01
+#define CP_2WHEEL_MOUSE_HACK           0x02
+#define CP_2WHEEL_MOUSE_HACK_ON                0x04
+
+/*
+ * Some USB barcode readers from cypress have usage min and usage max in
+ * the wrong order
+ */
+static void cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int rsize)
+{
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+       unsigned int i;
+
+       if (!(quirks & CP_RDESC_SWAPPED_MIN_MAX))
+               return;
+
+       for (i = 0; i < rsize - 4; i++)
+               if (rdesc[i] == 0x29 && rdesc[i + 2] == 0x19) {
+                       __u8 tmp;
+
+                       rdesc[i] = 0x19;
+                       rdesc[i + 2] = 0x29;
+                       tmp = rdesc[i + 3];
+                       rdesc[i + 3] = rdesc[i + 1];
+                       rdesc[i + 1] = tmp;
+               }
+}
+
+static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
+               struct hid_field *field, struct hid_usage *usage,
+               unsigned long **bit, int *max)
+{
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+
+       if (!(quirks & CP_2WHEEL_MOUSE_HACK))
+               return 0;
+
+       if (usage->type == EV_REL && usage->code == REL_WHEEL)
+               set_bit(REL_HWHEEL, *bit);
+       if (usage->hid == 0x00090005)
+               return -1;
+
+       return 0;
+}
+
+static int cp_event(struct hid_device *hdev, struct hid_field *field,
+               struct hid_usage *usage, __s32 value)
+{
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+
+       if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
+                       !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK))
+               return 0;
+
+       if (usage->hid == 0x00090005) {
+               if (value)
+                       quirks |=  CP_2WHEEL_MOUSE_HACK_ON;
+               else
+                       quirks &= ~CP_2WHEEL_MOUSE_HACK_ON;
+               hid_set_drvdata(hdev, (void *)quirks);
+               return 1;
+       }
+
+       if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) {
+               struct input_dev *input = field->hidinput->input;
+
+               input_event(input, usage->type, REL_HWHEEL, value);
+               return 1;
+       }
+
+       return 0;
+}
+
+static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
+{
+       unsigned long quirks = id->driver_data;
+       int ret;
+
+       hid_set_drvdata(hdev, (void *)quirks);
+
+       ret = hid_parse(hdev);
+       if (ret) {
+               dev_err(&hdev->dev, "parse failed\n");
+               goto err_free;
+       }
+
+       ret = hid_hw_start(hdev);
+       if (ret) {
+               dev_err(&hdev->dev, "hw start failed\n");
+               goto err_free;
+       }
+
+       return 0;
+err_free:
+       return ret;
+}
+
+static const struct hid_device_id cp_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1),
+               .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2),
+               .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE),
+               .driver_data = CP_2WHEEL_MOUSE_HACK },
+       { }
+};
+MODULE_DEVICE_TABLE(hid, cp_devices);
+
+static struct hid_driver cp_driver = {
+       .name = "cypress",
+       .id_table = cp_devices,
+       .report_fixup = cp_report_fixup,
+       .input_mapped = cp_input_mapped,
+       .event = cp_event,
+       .probe = cp_probe,
+};
+
+static int cp_init(void)
+{
+       return hid_register_driver(&cp_driver);
+}
+
+static void cp_exit(void)
+{
+       hid_unregister_driver(&cp_driver);
+}
+
+module_init(cp_init);
+module_exit(cp_exit);
+MODULE_LICENSE("GPL");
+
+HID_COMPAT_LOAD_DRIVER(cypress);
index 0c833d920c3d440ccd483674cdb2d6d59db282fd..27cffe3586f5b3631ed863f3e6d493ba5864e2f3 100644 (file)
@@ -7,6 +7,9 @@ static int __init hid_dummy_init(void)
 #ifdef CONFIG_HID_APPLE_MODULE
        HID_COMPAT_CALL_DRIVER(apple);
 #endif
+#ifdef CONFIG_HID_CYPRESS_MODULE
+       HID_COMPAT_CALL_DRIVER(cypress);
+#endif
 #ifdef CONFIG_HID_LOGITECH_MODULE
        HID_COMPAT_CALL_DRIVER(logitech);
 #endif
index a5e7163158fbec857b7c81abf2eea26de205d69b..6e7314f7b99807eb5b5ea6d5d62a636bd477bb36 100644 (file)
@@ -236,8 +236,8 @@ int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struc
 
        input = field->hidinput->input;
 
-       if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
-               || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) {
+       if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) &&
+                       (usage->hid == 0x00090007)) {
                if (value) hid->quirks |=  HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
                else       hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
                return 1;
index a6223bc5c734ef2ed23e45aeb36e1c17c87f2719..f1df25ab0baa8d1e20d86ec79d516d89a4118cbc 100644 (file)
@@ -515,13 +515,13 @@ mapped:
                                hidinput, field, usage, &bit, &max) < 0)
                goto ignore;
 
-       if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5 |
+       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_5) && (usage->hid == 0x00090005))
-               || ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007)))
+       if ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) &&
+                       (usage->hid == 0x00090007))
                goto ignore;
 
        set_bit(usage->type, input->evbit);
index 7f38c21e146bd5dcf19af1ef6febe8cdbdf73155..da80c64fb25c17d9261249b209a59e61a036bd77 100644 (file)
@@ -31,7 +31,6 @@ static const struct hid_blacklist {
 
        { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
        { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D, HID_QUIRK_2WHEEL_MOUSE_HACK_B8 },
-       { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
 
        { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
        { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
@@ -93,9 +92,6 @@ static const struct hid_rdesc_blacklist {
 
        { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_RDESC_SAMSUNG_REMOTE },
 
-       { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
-       { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
-
        { 0, 0 }
 };
 
@@ -382,30 +378,6 @@ static void usbhid_fixup_petalynx_descriptor(unsigned char *rdesc, int rsize)
        }
 }
 
-/*
- * Some USB barcode readers from cypress have usage min and usage max in
- * the wrong order
- */
-static void usbhid_fixup_cypress_descriptor(unsigned char *rdesc, int rsize)
-{
-       short fixed = 0;
-       int i;
-
-       for (i = 0; i < rsize - 4; i++) {
-               if (rdesc[i] == 0x29 && rdesc [i+2] == 0x19) {
-                       unsigned char tmp;
-
-                       rdesc[i] = 0x19; rdesc[i+2] = 0x29;
-                       tmp = rdesc[i+3];
-                       rdesc[i+3] = rdesc[i+1];
-                       rdesc[i+1] = tmp;
-               }
-       }
-
-       if (fixed)
-               printk(KERN_INFO "Fixing up Cypress report descriptor\n");
-}
-
 static void usbhid_fixup_button_consumer_descriptor(unsigned char *rdesc, int rsize)
 {
        if (rsize >= 30 && rdesc[29] == 0x05
@@ -420,9 +392,6 @@ static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned
        if ((quirks & HID_QUIRK_RDESC_CYMOTION))
                usbhid_fixup_cymotion_descriptor(rdesc, rsize);
 
-       if (quirks & HID_QUIRK_RDESC_SWAPPED_MIN_MAX)
-               usbhid_fixup_cypress_descriptor(rdesc, rsize);
-
        if (quirks & HID_QUIRK_RDESC_PETALYNX)
                usbhid_fixup_petalynx_descriptor(rdesc, rsize);
 
index a83d211021dea484bf64a0fc815e9419f22734da..27bfbcc1ef815aea834444dfdc1cf712486763fb 100644 (file)
@@ -262,7 +262,6 @@ struct hid_item {
 #define HID_QUIRK_BADPAD                       0x00000020
 #define HID_QUIRK_MULTI_INPUT                  0x00000040
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_7          0x00000080
-#define HID_QUIRK_2WHEEL_MOUSE_HACK_5          0x00000100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON         0x00000200
 #define HID_QUIRK_SKIP_OUTPUT_REPORTS          0x00010000
 #define HID_QUIRK_SONY_PS3_CONTROLLER          0x00040000
@@ -278,7 +277,6 @@ struct hid_item {
  */
 
 #define HID_QUIRK_RDESC_CYMOTION               0x00000001
-#define HID_QUIRK_RDESC_SWAPPED_MIN_MAX                0x00000004
 #define HID_QUIRK_RDESC_PETALYNX               0x00000008
 #define HID_QUIRK_RDESC_BUTTON_CONSUMER                0x00000020
 #define HID_QUIRK_RDESC_SAMSUNG_REMOTE         0x00000040