]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
HID: move thrustmaster FF processing
authorJiri Slaby <jirislaby@gmail.com>
Thu, 18 Sep 2008 10:23:31 +0000 (12:23 +0200)
committerJiri Kosina <jkosina@suse.cz>
Tue, 14 Oct 2008 21:51:00 +0000 (23:51 +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-dummy.c
drivers/hid/hid-ids.h
drivers/hid/hid-tmff.c [new file with mode: 0644]
drivers/hid/usbhid/Kconfig
drivers/hid/usbhid/Makefile
drivers/hid/usbhid/hid-ff.c
drivers/hid/usbhid/hid-tmff.c [deleted file]
include/linux/hid.h

index c836caba82d65b3bdd2ae4f6ebc07901f87632b9..78e3ba9504f314797104585d55c59b1143f59845 100644 (file)
@@ -243,6 +243,15 @@ config HID_SUNPLUS
        ---help---
        Support for Sunplus WDesktop input device.
 
+config THRUSTMASTER_FF
+       tristate "ThrustMaster devices support"
+       default m
+       depends on USB_HID
+       select INPUT_FF_MEMLESS
+       help
+         Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or
+         a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel.
+
 endmenu
 
 endif # HID_SUPPORT
index e60706835243d283b4330f4e4c1a826ef6c0e91f..9bd6daf6aaa4bf3c7987b49e4bb7953b71267933 100644 (file)
@@ -37,6 +37,7 @@ obj-$(CONFIG_HID_PETALYNX)    += hid-petalynx.o
 obj-$(CONFIG_HID_SAMSUNG)      += hid-samsung.o
 obj-$(CONFIG_HID_SONY)         += hid-sony.o
 obj-$(CONFIG_HID_SUNPLUS)      += hid-sunplus.o
+obj-$(CONFIG_THRUSTMASTER_FF)  += hid-tmff.o
 
 obj-$(CONFIG_USB_HID)          += usbhid/
 obj-$(CONFIG_USB_MOUSE)                += usbhid/
index 48a76e791e0268f9183123b1ff6983f49610295e..b0996ff1462bdc15bd896e4a56d09baf5662f5f3 100644 (file)
@@ -1516,6 +1516,10 @@ static const struct hid_device_id hid_ignore_list[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD) },
        { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) },
        { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
        { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
        { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
        { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
index 2f5d9a1a352c518f0691c57007b722e2fcb9e30c..ae122a122faac829e4ccd2957d968793e3799095 100644 (file)
@@ -55,6 +55,9 @@ static int __init hid_dummy_init(void)
 #ifdef CONFIG_HID_SUNPLUS_MODULE
        HID_COMPAT_CALL_DRIVER(sunplus);
 #endif
+#ifdef CONFIG_THRUSTMASTER_FF_MODULE
+       HID_COMPAT_CALL_DRIVER(thrustmaster);
+#endif
 
        return -EIO;
 }
index fdd2d13036f7596da3ca3024308062d5e1857c45..b8cc0196ec003f9c798ecbde37d5e0e0c4bee95f 100644 (file)
 #define USB_DEVICE_ID_TENX_IBUDDY1     0x0001
 #define USB_DEVICE_ID_TENX_IBUDDY2     0x0002
 
+#define USB_VENDOR_ID_THRUSTMASTER     0x044f
+
 #define USB_VENDOR_ID_TOPMAX           0x0663
 #define USB_DEVICE_ID_TOPMAX_COBRAPAD  0x0103
 
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
new file mode 100644 (file)
index 0000000..be7ebe2
--- /dev/null
@@ -0,0 +1,267 @@
+/*
+ * Force feedback support for various HID compliant devices by ThrustMaster:
+ *    ThrustMaster FireStorm Dual Power 2
+ * and possibly others whose device ids haven't been added.
+ *
+ *  Modified to support ThrustMaster devices by Zinx Verituse
+ *  on 2003-01-25 from the Logitech force feedback driver,
+ *  which is by Johann Deneux.
+ *
+ *  Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org>
+ *  Copyright (c) 2002 Johann Deneux
+ */
+
+/*
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/hid.h>
+#include <linux/input.h>
+#include <linux/usb.h>
+
+#include "hid-ids.h"
+
+#include "usbhid/usbhid.h"
+
+/* Usages for thrustmaster devices I know about */
+#define THRUSTMASTER_USAGE_FF  (HID_UP_GENDESK | 0xbb)
+
+static const signed short ff_rumble[] = {
+       FF_RUMBLE,
+       -1
+};
+
+static const signed short ff_joystick[] = {
+       FF_CONSTANT,
+       -1
+};
+
+struct tmff_device {
+       struct hid_report *report;
+       struct hid_field *ff_field;
+};
+
+/* Changes values from 0 to 0xffff into values from minimum to maximum */
+static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum)
+{
+       int ret;
+
+       ret = (in * (maximum - minimum) / 0xffff) + minimum;
+       if (ret < minimum)
+               return minimum;
+       if (ret > maximum)
+               return maximum;
+       return ret;
+}
+
+/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
+static inline int tmff_scale_s8(int in, int minimum, int maximum)
+{
+       int ret;
+
+       ret = (((in + 0x80) * (maximum - minimum)) / 0xff) + minimum;
+       if (ret < minimum)
+               return minimum;
+       if (ret > maximum)
+               return maximum;
+       return ret;
+}
+
+static int tmff_play(struct input_dev *dev, void *data,
+               struct ff_effect *effect)
+{
+       struct hid_device *hid = input_get_drvdata(dev);
+       struct tmff_device *tmff = data;
+       struct hid_field *ff_field = tmff->ff_field;
+       int x, y;
+       int left, right;        /* Rumbling */
+
+       switch (effect->type) {
+       case FF_CONSTANT:
+               x = tmff_scale_s8(effect->u.ramp.start_level,
+                                       ff_field->logical_minimum,
+                                       ff_field->logical_maximum);
+               y = tmff_scale_s8(effect->u.ramp.end_level,
+                                       ff_field->logical_minimum,
+                                       ff_field->logical_maximum);
+
+               dbg_hid("(x, y)=(%04x, %04x)\n", x, y);
+               ff_field->value[0] = x;
+               ff_field->value[1] = y;
+               usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
+               break;
+
+       case FF_RUMBLE:
+               left = tmff_scale_u16(effect->u.rumble.weak_magnitude,
+                                       ff_field->logical_minimum,
+                                       ff_field->logical_maximum);
+               right = tmff_scale_u16(effect->u.rumble.strong_magnitude,
+                                       ff_field->logical_minimum,
+                                       ff_field->logical_maximum);
+
+               dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
+               ff_field->value[0] = left;
+               ff_field->value[1] = right;
+               usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
+               break;
+       }
+       return 0;
+}
+
+static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
+{
+       struct tmff_device *tmff;
+       struct hid_report *report;
+       struct list_head *report_list;
+       struct hid_input *hidinput = list_entry(hid->inputs.next,
+                                                       struct hid_input, list);
+       struct input_dev *input_dev = hidinput->input;
+       int error;
+       int i;
+
+       tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
+       if (!tmff)
+               return -ENOMEM;
+
+       /* Find the report to use */
+       report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
+       list_for_each_entry(report, report_list, list) {
+               int fieldnum;
+
+               for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
+                       struct hid_field *field = report->field[fieldnum];
+
+                       if (field->maxusage <= 0)
+                               continue;
+
+                       switch (field->usage[0].hid) {
+                       case THRUSTMASTER_USAGE_FF:
+                               if (field->report_count < 2) {
+                                       warn("ignoring FF field with "
+                                                       "report_count < 2");
+                                       continue;
+                               }
+
+                               if (field->logical_maximum ==
+                                               field->logical_minimum) {
+                                       warn("ignoring FF field with "
+                                                       "logical_maximum == "
+                                                       "logical_minimum");
+                                       continue;
+                               }
+
+                               if (tmff->report && tmff->report != report) {
+                                       warn("ignoring FF field in other "
+                                                       "report");
+                                       continue;
+                               }
+
+                               if (tmff->ff_field && tmff->ff_field != field) {
+                                       warn("ignoring duplicate FF field");
+                                       continue;
+                               }
+
+                               tmff->report = report;
+                               tmff->ff_field = field;
+
+                               for (i = 0; ff_bits[i] >= 0; i++)
+                                       set_bit(ff_bits[i], input_dev->ffbit);
+
+                               break;
+
+                       default:
+                               warn("ignoring unknown output usage %08x",
+                                               field->usage[0].hid);
+                               continue;
+                       }
+               }
+       }
+
+       if (!tmff->report) {
+               err("cant find FF field in output reports\n");
+               error = -ENODEV;
+               goto fail;
+       }
+
+       error = input_ff_create_memless(input_dev, tmff, tmff_play);
+       if (error)
+               goto fail;
+
+       info("Force feedback for ThrustMaster devices by Zinx Verituse "
+                       "<zinx@epicsol.org>");
+       return 0;
+
+fail:
+       kfree(tmff);
+       return error;
+}
+
+static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id)
+{
+       int ret;
+
+       ret = hid_parse(hdev);
+       if (ret) {
+               dev_err(&hdev->dev, "parse failed\n");
+               goto err;
+       }
+
+       ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
+       if (ret) {
+               dev_err(&hdev->dev, "hw start failed\n");
+               goto err;
+       }
+
+       tmff_init(hdev, (void *)id->driver_data);
+
+       return 0;
+err:
+       return ret;
+}
+
+static const struct hid_device_id tm_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300),
+               .driver_data = (unsigned long)ff_rumble },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),
+               .driver_data = (unsigned long)ff_rumble },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651),   /* FGT Rumble Force Wheel */
+               .driver_data = (unsigned long)ff_rumble },
+       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654),   /* FGT Force Feedback Wheel */
+               .driver_data = (unsigned long)ff_joystick },
+       { }
+};
+MODULE_DEVICE_TABLE(hid, tm_devices);
+
+static struct hid_driver tm_driver = {
+       .name = "thrustmaster",
+       .id_table = tm_devices,
+       .probe = tm_probe,
+};
+
+static int tm_init(void)
+{
+       return hid_register_driver(&tm_driver);
+}
+
+static void tm_exit(void)
+{
+       hid_unregister_driver(&tm_driver);
+}
+
+module_init(tm_init);
+module_exit(tm_exit);
+MODULE_LICENSE("GPL");
+
+HID_COMPAT_LOAD_DRIVER(thrustmaster);
index 02c8228ed7eeefbf6b43301b73ced1c2a92933e9..c236fb3deb59a037be48d28d96527cdb9e37cc34 100644 (file)
@@ -44,17 +44,6 @@ config HID_PID
          feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such
          devices.
 
-config THRUSTMASTER_FF
-       bool "ThrustMaster devices support"
-       depends on HID_FF
-       select INPUT_FF_MEMLESS if USB_HID
-       help
-         Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or
-         a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel,
-         and want to enable force feedback support for it.
-         Note: if you say N here, this device will still be supported, but without
-         force feedback.
-
 config ZEROPLUS_FF
        bool "Zeroplus based game controller support"
        depends on HID_FF
index 0ee4803375b281e35eda2fa572eec63f1c349b6a..dd3b8634800f2cf3fc67bd998ced9c9897c0ddc3 100644 (file)
@@ -13,9 +13,6 @@ endif
 ifeq ($(CONFIG_HID_PID),y)
        usbhid-objs     += hid-pidff.o
 endif
-ifeq ($(CONFIG_THRUSTMASTER_FF),y)
-       usbhid-objs     += hid-tmff.o
-endif
 ifeq ($(CONFIG_ZEROPLUS_FF),y)
        usbhid-objs     += hid-zpff.o
 endif
index a868eef061891ad9350b9a0a499b97c022b94f28..ed3a869d54e31b7fb6eed4cf8d5722a721f7e4cb 100644 (file)
@@ -50,12 +50,6 @@ struct hid_ff_initializer {
  * be a PID device
  */
 static struct hid_ff_initializer inits[] = {
-#ifdef CONFIG_THRUSTMASTER_FF
-       { 0x44f, 0xb300, hid_tmff_init },
-       { 0x44f, 0xb304, hid_tmff_init },
-       { 0x44f, 0xb651, hid_tmff_init }, /* FGT Rumble Force Wheel */
-       { 0x44f, 0xb654, hid_tmff_init }, /* FGT Force Feedback Wheel */
-#endif
 #ifdef CONFIG_ZEROPLUS_FF
        { 0xc12, 0x0005, hid_zpff_init },
        { 0xc12, 0x0030, hid_zpff_init },
diff --git a/drivers/hid/usbhid/hid-tmff.c b/drivers/hid/usbhid/hid-tmff.c
deleted file mode 100644 (file)
index 144578b..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Force feedback support for various HID compliant devices by ThrustMaster:
- *    ThrustMaster FireStorm Dual Power 2
- * and possibly others whose device ids haven't been added.
- *
- *  Modified to support ThrustMaster devices by Zinx Verituse
- *  on 2003-01-25 from the Logitech force feedback driver,
- *  which is by Johann Deneux.
- *
- *  Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org>
- *  Copyright (c) 2002 Johann Deneux
- */
-
-/*
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <linux/input.h>
-
-#undef DEBUG
-#include <linux/usb.h>
-
-#include <linux/hid.h>
-#include "usbhid.h"
-
-/* Usages for thrustmaster devices I know about */
-#define THRUSTMASTER_USAGE_FF  (HID_UP_GENDESK | 0xbb)
-
-struct dev_type {
-       u16 idVendor;
-       u16 idProduct;
-       const signed short *ff;
-};
-
-static const signed short ff_rumble[] = {
-       FF_RUMBLE,
-       -1
-};
-
-static const signed short ff_joystick[] = {
-       FF_CONSTANT,
-       -1
-};
-
-static const struct dev_type devices[] = {
-       { 0x44f, 0xb300, ff_rumble },
-       { 0x44f, 0xb304, ff_rumble },
-       { 0x44f, 0xb651, ff_rumble },   /* FGT Rumble Force Wheel */
-       { 0x44f, 0xb654, ff_joystick }, /* FGT Force Feedback Wheel */
-};
-
-struct tmff_device {
-       struct hid_report *report;
-       struct hid_field *ff_field;
-};
-
-/* Changes values from 0 to 0xffff into values from minimum to maximum */
-static inline int hid_tmff_scale_u16(unsigned int in,
-                               int minimum, int maximum)
-{
-       int ret;
-
-       ret = (in * (maximum - minimum) / 0xffff) + minimum;
-       if (ret < minimum)
-               return minimum;
-       if (ret > maximum)
-               return maximum;
-       return ret;
-}
-
-/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
-static inline int hid_tmff_scale_s8(int in,
-                                   int minimum, int maximum)
-{
-       int ret;
-
-       ret = (((in + 0x80) * (maximum - minimum)) / 0xff) + minimum;
-       if (ret < minimum)
-               return minimum;
-       if (ret > maximum)
-               return maximum;
-       return ret;
-}
-
-static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
-{
-       struct hid_device *hid = input_get_drvdata(dev);
-       struct tmff_device *tmff = data;
-       struct hid_field *ff_field = tmff->ff_field;
-       int x, y;
-       int left, right;        /* Rumbling */
-
-       switch (effect->type) {
-       case FF_CONSTANT:
-               x = hid_tmff_scale_s8(effect->u.ramp.start_level,
-                                       ff_field->logical_minimum,
-                                       ff_field->logical_maximum);
-               y = hid_tmff_scale_s8(effect->u.ramp.end_level,
-                                       ff_field->logical_minimum,
-                                       ff_field->logical_maximum);
-
-               dbg_hid("(x, y)=(%04x, %04x)\n", x, y);
-               ff_field->value[0] = x;
-               ff_field->value[1] = y;
-               usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
-               break;
-
-       case FF_RUMBLE:
-               left = hid_tmff_scale_u16(effect->u.rumble.weak_magnitude,
-                                       ff_field->logical_minimum,
-                                       ff_field->logical_maximum);
-               right = hid_tmff_scale_u16(effect->u.rumble.strong_magnitude,
-                                       ff_field->logical_minimum,
-                                       ff_field->logical_maximum);
-
-               dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
-               ff_field->value[0] = left;
-               ff_field->value[1] = right;
-               usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
-               break;
-       }
-       return 0;
-}
-
-int hid_tmff_init(struct hid_device *hid)
-{
-       struct tmff_device *tmff;
-       struct hid_report *report;
-       struct list_head *report_list;
-       struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
-       struct input_dev *input_dev = hidinput->input;
-       const signed short *ff_bits = ff_joystick;
-       int error;
-       int i;
-
-       tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
-       if (!tmff)
-               return -ENOMEM;
-
-       /* Find the report to use */
-       report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
-       list_for_each_entry(report, report_list, list) {
-               int fieldnum;
-
-               for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
-                       struct hid_field *field = report->field[fieldnum];
-
-                       if (field->maxusage <= 0)
-                               continue;
-
-                       switch (field->usage[0].hid) {
-                       case THRUSTMASTER_USAGE_FF:
-                               if (field->report_count < 2) {
-                                       warn("ignoring FF field with report_count < 2");
-                                       continue;
-                               }
-
-                               if (field->logical_maximum == field->logical_minimum) {
-                                       warn("ignoring FF field with logical_maximum == logical_minimum");
-                                       continue;
-                               }
-
-                               if (tmff->report && tmff->report != report) {
-                                       warn("ignoring FF field in other report");
-                                       continue;
-                               }
-
-                               if (tmff->ff_field && tmff->ff_field != field) {
-                                       warn("ignoring duplicate FF field");
-                                       continue;
-                               }
-
-                               tmff->report = report;
-                               tmff->ff_field = field;
-
-                               for (i = 0; i < ARRAY_SIZE(devices); i++) {
-                                       if (input_dev->id.vendor == devices[i].idVendor &&
-                                           input_dev->id.product == devices[i].idProduct) {
-                                               ff_bits = devices[i].ff;
-                                               break;
-                                       }
-                               }
-
-                               for (i = 0; ff_bits[i] >= 0; i++)
-                                       set_bit(ff_bits[i], input_dev->ffbit);
-
-                               break;
-
-                       default:
-                               warn("ignoring unknown output usage %08x", field->usage[0].hid);
-                               continue;
-                       }
-               }
-       }
-
-       if (!tmff->report) {
-               err("cant find FF field in output reports\n");
-               error = -ENODEV;
-               goto fail;
-       }
-
-       error = input_ff_create_memless(input_dev, tmff, hid_tmff_play);
-       if (error)
-               goto fail;
-
-       info("Force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>");
-       return 0;
-
- fail:
-       kfree(tmff);
-       return error;
-}
-
index 63b808067203d1b707a2cc47194fd481bd6ce4d9..8266e50637b436db1e65be2243542869e7b2f81a 100644 (file)
@@ -760,7 +760,6 @@ void usbhid_set_leds(struct hid_device *hid);
 #ifdef CONFIG_HID_FF
 int hid_ff_init(struct hid_device *hid);
 
-int hid_tmff_init(struct hid_device *hid);
 int hid_zpff_init(struct hid_device *hid);
 #ifdef CONFIG_HID_PID
 int hid_pidff_init(struct hid_device *hid);