Commit b27c9590 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Jiri Kosina

HID: add support for Thrustmaster FGT Force Feedback wheel

Rework thrustmaster force-feedback module to support devices having
different types of force feedback effects. Add signatures of
Thrustmaster FGT Rumble Force and Thrustmaster FGT Force Feedback
wheels to the list of devices dupported by the module.

Parts of the patch were lifted off a simalar patch by
Anssi Hannula <anssi.hannula@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 933e3187
...@@ -79,11 +79,12 @@ config PANTHERLORD_FF ...@@ -79,11 +79,12 @@ config PANTHERLORD_FF
to enable force feedback support for it. to enable force feedback support for it.
config THRUSTMASTER_FF config THRUSTMASTER_FF
bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)" bool "ThrustMaster devices support (EXPERIMENTAL)"
depends on HID_FF && EXPERIMENTAL depends on HID_FF && EXPERIMENTAL
select INPUT_FF_MEMLESS if USB_HID select INPUT_FF_MEMLESS if USB_HID
help help
Say Y here if you have a THRUSTMASTER FireStore Dual Power 2, 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. and want to enable force feedback support for it.
Note: if you say N here, this device will still be supported, but without Note: if you say N here, this device will still be supported, but without
force feedback. force feedback.
......
...@@ -67,6 +67,8 @@ static struct hid_ff_initializer inits[] = { ...@@ -67,6 +67,8 @@ static struct hid_ff_initializer inits[] = {
#ifdef CONFIG_THRUSTMASTER_FF #ifdef CONFIG_THRUSTMASTER_FF
{ 0x44f, 0xb300, hid_tmff_init }, { 0x44f, 0xb300, hid_tmff_init },
{ 0x44f, 0xb304, 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 #endif
#ifdef CONFIG_ZEROPLUS_FF #ifdef CONFIG_ZEROPLUS_FF
{ 0xc12, 0x0005, hid_zpff_init }, { 0xc12, 0x0005, hid_zpff_init },
......
...@@ -36,16 +36,39 @@ ...@@ -36,16 +36,39 @@
#include "usbhid.h" #include "usbhid.h"
/* Usages for thrustmaster devices I know about */ /* Usages for thrustmaster devices I know about */
#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb) #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 tmff_device {
struct hid_report *report; struct hid_report *report;
struct hid_field *rumble; struct hid_field *ff_field;
}; };
/* Changes values from 0 to 0xffff into values from minimum to maximum */ /* Changes values from 0 to 0xffff into values from minimum to maximum */
static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum) static inline int hid_tmff_scale_u16(unsigned int in,
int minimum, int maximum)
{ {
int ret; int ret;
...@@ -57,22 +80,57 @@ static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum) ...@@ -57,22 +80,57 @@ static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
return ret; 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) static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
{ {
struct hid_device *hid = input_get_drvdata(dev); struct hid_device *hid = input_get_drvdata(dev);
struct tmff_device *tmff = data; struct tmff_device *tmff = data;
struct hid_field *ff_field = tmff->ff_field;
int x, y;
int left, right; /* Rumbling */ int left, right; /* Rumbling */
left = hid_tmff_scale(effect->u.rumble.weak_magnitude, switch (effect->type) {
tmff->rumble->logical_minimum, tmff->rumble->logical_maximum); case FF_CONSTANT:
right = hid_tmff_scale(effect->u.rumble.strong_magnitude, x = hid_tmff_scale_s8(effect->u.ramp.start_level,
tmff->rumble->logical_minimum, tmff->rumble->logical_maximum); ff_field->logical_minimum,
ff_field->logical_maximum);
tmff->rumble->value[0] = left; y = hid_tmff_scale_s8(effect->u.ramp.end_level,
tmff->rumble->value[1] = right; ff_field->logical_minimum,
dbg_hid("(left,right)=(%08x, %08x)\n", left, right); ff_field->logical_maximum);
usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
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; return 0;
} }
...@@ -82,14 +140,16 @@ int hid_tmff_init(struct hid_device *hid) ...@@ -82,14 +140,16 @@ int hid_tmff_init(struct hid_device *hid)
struct list_head *pos; struct list_head *pos;
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
struct input_dev *input_dev = hidinput->input; struct input_dev *input_dev = hidinput->input;
const signed short *ff_bits = ff_joystick;
int error; int error;
int i;
tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL); tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
if (!tmff) if (!tmff)
return -ENOMEM; return -ENOMEM;
/* Find the report to use */ /* Find the report to use */
__list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) { list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) {
struct hid_report *report = (struct hid_report *)pos; struct hid_report *report = (struct hid_report *)pos;
int fieldnum; int fieldnum;
...@@ -100,48 +160,65 @@ int hid_tmff_init(struct hid_device *hid) ...@@ -100,48 +160,65 @@ int hid_tmff_init(struct hid_device *hid)
continue; continue;
switch (field->usage[0].hid) { switch (field->usage[0].hid) {
case THRUSTMASTER_USAGE_RUMBLE_LR: case THRUSTMASTER_USAGE_FF:
if (field->report_count < 2) { if (field->report_count < 2) {
warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with report_count < 2"); warn("ignoring FF field with report_count < 2");
continue; continue;
} }
if (field->logical_maximum == field->logical_minimum) { if (field->logical_maximum == field->logical_minimum) {
warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with logical_maximum == logical_minimum"); warn("ignoring FF field with logical_maximum == logical_minimum");
continue; continue;
} }
if (tmff->report && tmff->report != report) { if (tmff->report && tmff->report != report) {
warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report"); warn("ignoring FF field in other report");
continue; continue;
} }
if (tmff->rumble && tmff->rumble != field) { if (tmff->ff_field && tmff->ff_field != field) {
warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR"); warn("ignoring duplicate FF field");
continue; 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;
} }
}
tmff->report = report; for (i = 0; ff_bits[i] >= 0; i++)
tmff->rumble = field; set_bit(ff_bits[i], input_dev->ffbit);
set_bit(FF_RUMBLE, input_dev->ffbit); break;
break;
default: default:
warn("ignoring unknown output usage %08x", field->usage[0].hid); warn("ignoring unknown output usage %08x", field->usage[0].hid);
continue; continue;
} }
} }
} }
error = input_ff_create_memless(input_dev, tmff, hid_tmff_play); if (!tmff->report) {
if (error) { err("cant find FF field in output reports\n");
kfree(tmff); error = -ENODEV;
return error; goto fail;
} }
info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>"); 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; return 0;
fail:
kfree(tmff);
return error;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment