2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
#include <linux/hid.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/input.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-07-04 00:39:48 +07:00
|
|
|
#include <linux/module.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
#include "hid-ids.h"
|
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
static const signed short ff_rumble[] = {
|
|
|
|
FF_RUMBLE,
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const signed short ff_joystick[] = {
|
|
|
|
FF_CONSTANT,
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
2009-05-15 20:46:44 +07:00
|
|
|
#ifdef CONFIG_THRUSTMASTER_FF
|
|
|
|
|
|
|
|
/* Usages for thrustmaster devices I know about */
|
|
|
|
#define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb)
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct tmff_device {
|
|
|
|
struct hid_report *report;
|
2007-07-30 19:56:26 +07:00
|
|
|
struct hid_field *ff_field;
|
2006-07-19 12:40:55 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-19 12:40:55 +07:00
|
|
|
/* Changes values from 0 to 0xffff into values from minimum to maximum */
|
2008-09-18 17:23:31 +07:00
|
|
|
static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum)
|
2006-07-19 12:40:55 +07:00
|
|
|
{
|
|
|
|
int ret;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-19 12:40:55 +07:00
|
|
|
ret = (in * (maximum - minimum) / 0xffff) + minimum;
|
|
|
|
if (ret < minimum)
|
|
|
|
return minimum;
|
|
|
|
if (ret > maximum)
|
|
|
|
return maximum;
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
|
2008-09-18 17:23:31 +07:00
|
|
|
static inline int tmff_scale_s8(int in, int minimum, int maximum)
|
2007-07-30 19:56:26 +07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = (((in + 0x80) * (maximum - minimum)) / 0xff) + minimum;
|
|
|
|
if (ret < minimum)
|
|
|
|
return minimum;
|
|
|
|
if (ret > maximum)
|
|
|
|
return maximum;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
static int tmff_play(struct input_dev *dev, void *data,
|
|
|
|
struct ff_effect *effect)
|
2006-07-19 12:40:55 +07:00
|
|
|
{
|
2007-05-09 15:17:31 +07:00
|
|
|
struct hid_device *hid = input_get_drvdata(dev);
|
2006-07-19 12:40:55 +07:00
|
|
|
struct tmff_device *tmff = data;
|
2007-07-30 19:56:26 +07:00
|
|
|
struct hid_field *ff_field = tmff->ff_field;
|
|
|
|
int x, y;
|
2006-07-19 12:40:55 +07:00
|
|
|
int left, right; /* Rumbling */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
switch (effect->type) {
|
|
|
|
case FF_CONSTANT:
|
2008-09-18 17:23:31 +07:00
|
|
|
x = tmff_scale_s8(effect->u.ramp.start_level,
|
2007-07-30 19:56:26 +07:00
|
|
|
ff_field->logical_minimum,
|
|
|
|
ff_field->logical_maximum);
|
2008-09-18 17:23:31 +07:00
|
|
|
y = tmff_scale_s8(effect->u.ramp.end_level,
|
2007-07-30 19:56:26 +07:00
|
|
|
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;
|
2013-02-25 17:31:46 +07:00
|
|
|
hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
|
2007-07-30 19:56:26 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FF_RUMBLE:
|
2008-09-18 17:23:31 +07:00
|
|
|
left = tmff_scale_u16(effect->u.rumble.weak_magnitude,
|
2007-07-30 19:56:26 +07:00
|
|
|
ff_field->logical_minimum,
|
|
|
|
ff_field->logical_maximum);
|
2008-09-18 17:23:31 +07:00
|
|
|
right = tmff_scale_u16(effect->u.rumble.strong_magnitude,
|
2007-07-30 19:56:26 +07:00
|
|
|
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;
|
2013-02-25 17:31:46 +07:00
|
|
|
hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
|
2007-07-30 19:56:26 +07:00
|
|
|
break;
|
|
|
|
}
|
2006-07-19 12:40:55 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-07-19 12:40:55 +07:00
|
|
|
struct tmff_device *tmff;
|
2007-11-14 17:31:05 +07:00
|
|
|
struct hid_report *report;
|
|
|
|
struct list_head *report_list;
|
2008-09-18 17:23:31 +07:00
|
|
|
struct hid_input *hidinput = list_entry(hid->inputs.next,
|
|
|
|
struct hid_input, list);
|
2005-09-15 14:01:47 +07:00
|
|
|
struct input_dev *input_dev = hidinput->input;
|
2006-07-19 12:40:55 +07:00
|
|
|
int error;
|
2007-07-30 19:56:26 +07:00
|
|
|
int i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-19 12:40:55 +07:00
|
|
|
tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
|
|
|
|
if (!tmff)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Find the report to use */
|
2007-11-14 17:31:05 +07:00
|
|
|
report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
|
|
|
|
list_for_each_entry(report, report_list, list) {
|
2005-04-17 05:20:36 +07:00
|
|
|
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) {
|
2007-07-30 19:56:26 +07:00
|
|
|
case THRUSTMASTER_USAGE_FF:
|
|
|
|
if (field->report_count < 2) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_warn(hid, "ignoring FF field with report_count < 2\n");
|
2007-07-30 19:56:26 +07:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
if (field->logical_maximum ==
|
|
|
|
field->logical_minimum) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_warn(hid, "ignoring FF field with logical_maximum == logical_minimum\n");
|
2007-07-30 19:56:26 +07:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
if (tmff->report && tmff->report != report) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_warn(hid, "ignoring FF field in other report\n");
|
2007-07-30 19:56:26 +07:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
if (tmff->ff_field && tmff->ff_field != field) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_warn(hid, "ignoring duplicate FF field\n");
|
2007-07-30 19:56:26 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmff->report = report;
|
|
|
|
tmff->ff_field = field;
|
|
|
|
|
|
|
|
for (i = 0; ff_bits[i] >= 0; i++)
|
|
|
|
set_bit(ff_bits[i], input_dev->ffbit);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
default:
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_warn(hid, "ignoring unknown output usage %08x\n",
|
|
|
|
field->usage[0].hid);
|
2007-07-30 19:56:26 +07:00
|
|
|
continue;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-30 19:56:26 +07:00
|
|
|
if (!tmff->report) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_err(hid, "can't find FF field in output reports\n");
|
2007-07-30 19:56:26 +07:00
|
|
|
error = -ENODEV;
|
|
|
|
goto fail;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
error = input_ff_create_memless(input_dev, tmff, tmff_play);
|
2007-07-30 19:56:26 +07:00
|
|
|
if (error)
|
|
|
|
goto fail;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_info(hid, "force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2007-07-30 19:56:26 +07:00
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
fail:
|
2007-07-30 19:56:26 +07:00
|
|
|
kfree(tmff);
|
|
|
|
return error;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2009-05-15 20:46:44 +07:00
|
|
|
#else
|
|
|
|
static inline int tmff_init(struct hid_device *hid, const signed short *ff_bits)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-09-18 17:23:31 +07:00
|
|
|
static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = hid_parse(hdev);
|
|
|
|
if (ret) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_err(hdev, "parse failed\n");
|
2008-09-18 17:23:31 +07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
|
|
|
|
if (ret) {
|
2010-12-10 10:29:03 +07:00
|
|
|
hid_err(hdev, "hw start failed\n");
|
2008-09-18 17:23:31 +07:00
|
|
|
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 },
|
2009-06-29 14:41:29 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304), /* FireStorm Dual Power 2 (and 3) */
|
|
|
|
.driver_data = (unsigned long)ff_rumble },
|
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323), /* Dual Trigger 3-in-1 (PC Mode) */
|
|
|
|
.driver_data = (unsigned long)ff_rumble },
|
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324), /* Dual Trigger 3-in-1 (PS3 Mode) */
|
2008-09-18 17:23:31 +07:00
|
|
|
.driver_data = (unsigned long)ff_rumble },
|
2017-11-07 15:13:16 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605), /* NASCAR PRO FF2 Wheel */
|
|
|
|
.driver_data = (unsigned long)ff_joystick },
|
2008-09-18 17:23:31 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651), /* FGT Rumble Force Wheel */
|
|
|
|
.driver_data = (unsigned long)ff_rumble },
|
2010-03-13 23:29:43 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653), /* RGT Force Feedback CLUTCH Raging Wheel */
|
|
|
|
.driver_data = (unsigned long)ff_joystick },
|
2008-09-18 17:23:31 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */
|
|
|
|
.driver_data = (unsigned long)ff_joystick },
|
2010-11-29 23:41:23 +07:00
|
|
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a), /* F430 Force Feedback Wheel */
|
|
|
|
.driver_data = (unsigned long)ff_joystick },
|
2008-09-18 17:23:31 +07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(hid, tm_devices);
|
|
|
|
|
|
|
|
static struct hid_driver tm_driver = {
|
|
|
|
.name = "thrustmaster",
|
|
|
|
.id_table = tm_devices,
|
|
|
|
.probe = tm_probe,
|
|
|
|
};
|
2012-12-18 05:28:26 +07:00
|
|
|
module_hid_driver(tm_driver);
|
2008-09-18 17:23:31 +07:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|