HID: add new driver for non-compliant Saitek devices
authorAndreas Hübner <andreas@k4n.de>
Wed, 22 Feb 2012 01:10:06 +0000 (02:10 +0100)
committerJiri Kosina <jkosina@suse.cz>
Wed, 22 Feb 2012 10:30:17 +0000 (11:30 +0100)
The driver currently only supports the PS1000 controller.
It fixes the report descriptor by removing a non-existing axis and
clearing the constant bit on the d-pad and button input reports.

Signed-off-by: Andreas Hübner <andreas@k4n.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/Kconfig
drivers/hid/Makefile
drivers/hid/hid-core.c
drivers/hid/hid-ids.h
drivers/hid/hid-saitek.c [new file with mode: 0644]

index 1e6b78ed5ac9acac2c9a6ca889ba875693b6612e..9398cfce80b683654751dad8a667683a0b112fb9 100644 (file)
@@ -532,6 +532,15 @@ config HID_ROCCAT_PYRA
        ---help---
        Support for Roccat Pyra mouse.
 
+config HID_SAITEK
+       tristate "Saitek non-fully HID-compliant devices"
+       depends on USB_HID
+       ---help---
+       Support for Saitek devices that are not fully compliant with the
+       HID standard.
+
+       Currently only supports the PS1000 controller.
+
 config HID_SAMSUNG
        tristate "Samsung InfraRed remote control or keyboards"
        depends on USB_HID
index c05f448f34a0919aadeb61e1dd3311591456ae0b..524532b49eaa250ce06c15dfc6d8ad98153c184d 100644 (file)
@@ -72,6 +72,7 @@ obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o
 obj-$(CONFIG_HID_ROCCAT_KONEPLUS)      += hid-roccat-koneplus.o
 obj-$(CONFIG_HID_ROCCAT_KOVAPLUS)      += hid-roccat-kovaplus.o
 obj-$(CONFIG_HID_ROCCAT_PYRA)  += hid-roccat-pyra.o
+obj-$(CONFIG_HID_SAITEK)       += hid-saitek.o
 obj-$(CONFIG_HID_SAMSUNG)      += hid-samsung.o
 obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o
 obj-$(CONFIG_HID_SONY)         += hid-sony.o
index 549c7538e57f1ac764ef4c69e7cbbfad7ccaf5bd..58d8f50649eb683c86b3fdad0fe18f2754d86d9e 100644 (file)
@@ -1519,6 +1519,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
index 6de95422586a36ae6eef7d894f4982a014fd3d9e..bc6e2b5862aa52ef876b91807f330b3b360623a9 100644 (file)
 
 #define USB_VENDOR_ID_SAITEK           0x06a3
 #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
+#define USB_DEVICE_ID_SAITEK_PS1000    0xff17
 
 #define USB_VENDOR_ID_SAMSUNG          0x0419
 #define USB_DEVICE_ID_SAMSUNG_IR_REMOTE        0x0001
diff --git a/drivers/hid/hid-saitek.c b/drivers/hid/hid-saitek.c
new file mode 100644 (file)
index 0000000..45aea77
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  HID driver for Saitek devices, currently only the PS1000 (USB gamepad).
+ *  Fixes the HID report descriptor by removing a non-existent axis and
+ *  clearing the constant bit on the input reports for buttons and d-pad.
+ *  (This module is based on "hid-ortek".)
+ *
+ *  Copyright (c) 2012 Andreas Hübner
+ */
+
+/*
+ * 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/module.h>
+#include <linux/kernel.h>
+
+#include "hid-ids.h"
+
+static __u8 *saitek_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int *rsize)
+{
+       if (*rsize == 137 && rdesc[20] == 0x09 && rdesc[21] == 0x33
+                       && rdesc[94] == 0x81 && rdesc[95] == 0x03
+                       && rdesc[110] == 0x81 && rdesc[111] == 0x03) {
+
+               hid_info(hdev, "Fixing up Saitek PS1000 report descriptor\n");
+
+               /* convert spurious axis to a "noop" Logical Minimum (0) */
+               rdesc[20] = 0x15;
+               rdesc[21] = 0x00;
+
+               /* clear constant bit on buttons and d-pad */
+               rdesc[95] = 0x02;
+               rdesc[111] = 0x02;
+
+       }
+       return rdesc;
+}
+
+static const struct hid_device_id saitek_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000)},
+       { }
+};
+
+MODULE_DEVICE_TABLE(hid, saitek_devices);
+
+static struct hid_driver saitek_driver = {
+       .name = "saitek",
+       .id_table = saitek_devices,
+       .report_fixup = saitek_report_fixup
+};
+
+static int __init saitek_init(void)
+{
+       return hid_register_driver(&saitek_driver);
+}
+
+static void __exit saitek_exit(void)
+{
+       hid_unregister_driver(&saitek_driver);
+}
+
+module_init(saitek_init);
+module_exit(saitek_exit);
+MODULE_LICENSE("GPL");