30 #include <linux/hid.h>
31 #include <linux/input.h>
32 #include <linux/slab.h>
34 #include <linux/module.h>
38 static const signed short ff_rumble[] = {
43 static const signed short ff_joystick[] = {
48 #ifdef CONFIG_THRUSTMASTER_FF
52 #define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb)
73 static inline int tmff_scale_s8(
int in,
int minimum,
int maximum)
77 ret = (((in + 0x80) * (maximum - minimum)) / 0xff) +
minimum;
85 static int tmff_play(
struct input_dev *
dev,
void *
data,
88 struct hid_device *hid = input_get_drvdata(dev);
89 struct tmff_device *tmff =
data;
90 struct hid_field *ff_field = tmff->ff_field;
94 switch (effect->
type) {
96 x = tmff_scale_s8(effect->
u.
ramp.start_level,
99 y = tmff_scale_s8(effect->
u.
ramp.end_level,
103 dbg_hid(
"(x, y)=(%04x, %04x)\n", x, y);
110 left = tmff_scale_u16(effect->
u.
rumble.weak_magnitude,
113 right = tmff_scale_u16(effect->
u.
rumble.strong_magnitude,
117 dbg_hid(
"(left,right)=(%08x, %08x)\n", left, right);
126 static int tmff_init(
struct hid_device *hid,
const signed short *ff_bits)
128 struct tmff_device *tmff;
133 struct input_dev *input_dev = hidinput->
input;
137 tmff = kzalloc(
sizeof(
struct tmff_device),
GFP_KERNEL);
146 for (fieldnum = 0; fieldnum < report->
maxfield; ++fieldnum) {
152 switch (field->
usage[0].hid) {
153 case THRUSTMASTER_USAGE_FF:
155 hid_warn(hid,
"ignoring FF field with report_count < 2\n");
161 hid_warn(hid,
"ignoring FF field with logical_maximum == logical_minimum\n");
165 if (tmff->report && tmff->report != report) {
166 hid_warn(hid,
"ignoring FF field in other report\n");
170 if (tmff->ff_field && tmff->ff_field != field) {
171 hid_warn(hid,
"ignoring duplicate FF field\n");
176 tmff->ff_field =
field;
178 for (i = 0; ff_bits[
i] >= 0; i++)
179 set_bit(ff_bits[i], input_dev->ffbit);
184 hid_warn(hid,
"ignoring unknown output usage %08x\n",
185 field->
usage[0].hid);
192 hid_err(hid,
"can't find FF field in output reports\n");
209 static inline int tmff_init(
struct hid_device *hid,
const signed short *ff_bits)
219 ret = hid_parse(hdev);
221 hid_err(hdev,
"parse failed\n");
227 hid_err(hdev,
"hw start failed\n");
231 tmff_init(hdev, (
void *)id->driver_data);
240 .driver_data = (
unsigned long)ff_rumble },
242 .driver_data = (
unsigned long)ff_rumble },
244 .driver_data = (
unsigned long)ff_rumble },
246 .driver_data = (
unsigned long)ff_rumble },
248 .driver_data = (
unsigned long)ff_rumble },
250 .driver_data = (
unsigned long)ff_joystick },
252 .driver_data = (
unsigned long)ff_joystick },
254 .driver_data = (
unsigned long)ff_joystick },
260 .name =
"thrustmaster",
261 .id_table = tm_devices,
265 static int __init tm_init(
void)
270 static void __exit tm_exit(
void)