2 * Force feedback support for Logitech Speed Force Wireless
4 * http://wiibrew.org/wiki/Logitech_USB_steering_wheel
6 * Copyright (c) 2010 Simon Wood <simon@mungewell.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/input.h>
27 #include <linux/usb.h>
28 #include <linux/hid.h>
30 #include "usbhid/usbhid.h"
34 struct hid_report
*report
;
37 static const signed short ff4_wheel_ac
[] = {
43 static int hid_lg4ff_play(struct input_dev
*dev
, void *data
,
44 struct ff_effect
*effect
)
46 struct hid_device
*hid
= input_get_drvdata(dev
);
47 struct list_head
*report_list
= &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
;
48 struct hid_report
*report
= list_entry(report_list
->next
, struct hid_report
, list
);
51 #define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
53 switch (effect
->type
) {
55 x
= effect
->u
.ramp
.start_level
+ 0x80; /* 0x80 is no force */
57 report
->field
[0]->value
[0] = 0x11; /* Slot 1 */
58 report
->field
[0]->value
[1] = 0x10;
59 report
->field
[0]->value
[2] = x
;
60 report
->field
[0]->value
[3] = 0x00;
61 report
->field
[0]->value
[4] = 0x00;
62 report
->field
[0]->value
[5] = 0x08;
63 report
->field
[0]->value
[6] = 0x00;
64 dbg_hid("Autocenter, x=0x%02X\n", x
);
66 usbhid_submit_report(hid
, report
, USB_DIR_OUT
);
72 static void hid_lg4ff_set_autocenter(struct input_dev
*dev
, u16 magnitude
)
74 struct hid_device
*hid
= input_get_drvdata(dev
);
75 struct list_head
*report_list
= &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
;
76 struct hid_report
*report
= list_entry(report_list
->next
, struct hid_report
, list
);
77 __s32
*value
= report
->field
[0]->value
;
83 *value
++ = (magnitude
>> 8) & 0xff;
87 usbhid_submit_report(hid
, report
, USB_DIR_OUT
);
91 int lg4ff_init(struct hid_device
*hid
)
93 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
94 struct list_head
*report_list
= &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
;
95 struct input_dev
*dev
= hidinput
->input
;
96 struct hid_report
*report
;
97 struct hid_field
*field
;
98 const signed short *ff_bits
= ff4_wheel_ac
;
102 /* Find the report to use */
103 if (list_empty(report_list
)) {
104 err_hid("No output report found");
108 /* Check that the report looks ok */
109 report
= list_entry(report_list
->next
, struct hid_report
, list
);
111 err_hid("NULL output report");
115 field
= report
->field
[0];
117 err_hid("NULL field");
121 for (i
= 0; ff_bits
[i
] >= 0; i
++)
122 set_bit(ff_bits
[i
], dev
->ffbit
);
124 error
= input_ff_create_memless(dev
, NULL
, hid_lg4ff_play
);
129 if (test_bit(FF_AUTOCENTER
, dev
->ffbit
))
130 dev
->ff
->set_autocenter
= hid_lg4ff_set_autocenter
;
132 dev_info(&hid
->dev
, "Force feedback for Logitech Speed Force Wireless by "
133 "Simon Wood <simon@mungewell.org>\n");