2 * Force feedback support for Logitech Rumblepad 2
4 * Copyright (c) 2008 Anssi Hannula <anssi.hannula@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/input.h>
25 #include <linux/usb.h>
26 #include <linux/hid.h>
30 struct hid_report
*report
;
33 static int play_effect(struct input_dev
*dev
, void *data
,
34 struct ff_effect
*effect
)
36 struct hid_device
*hid
= input_get_drvdata(dev
);
37 struct lg2ff_device
*lg2ff
= data
;
40 strong
= effect
->u
.rumble
.strong_magnitude
;
41 weak
= effect
->u
.rumble
.weak_magnitude
;
44 weak
= weak
* 0xff / 0xffff;
45 strong
= strong
* 0xff / 0xffff;
47 lg2ff
->report
->field
[0]->value
[0] = 0x51;
48 lg2ff
->report
->field
[0]->value
[2] = weak
;
49 lg2ff
->report
->field
[0]->value
[4] = strong
;
51 lg2ff
->report
->field
[0]->value
[0] = 0xf3;
52 lg2ff
->report
->field
[0]->value
[2] = 0x00;
53 lg2ff
->report
->field
[0]->value
[4] = 0x00;
56 usbhid_submit_report(hid
, lg2ff
->report
, USB_DIR_OUT
);
60 int hid_lg2ff_init(struct hid_device
*hid
)
62 struct lg2ff_device
*lg2ff
;
63 struct hid_report
*report
;
64 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
,
65 struct hid_input
, list
);
66 struct list_head
*report_list
=
67 &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
;
68 struct input_dev
*dev
= hidinput
->input
;
71 if (list_empty(report_list
)) {
72 printk(KERN_ERR
"hid-lg2ff: no output report found\n");
76 report
= list_entry(report_list
->next
, struct hid_report
, list
);
78 if (report
->maxfield
< 1) {
79 printk(KERN_ERR
"hid-lg2ff: output report is empty\n");
82 if (report
->field
[0]->report_count
< 7) {
83 printk(KERN_ERR
"hid-lg2ff: not enough values in the field\n");
87 lg2ff
= kmalloc(sizeof(struct lg2ff_device
), GFP_KERNEL
);
91 set_bit(FF_RUMBLE
, dev
->ffbit
);
93 error
= input_ff_create_memless(dev
, lg2ff
, play_effect
);
99 lg2ff
->report
= report
;
100 report
->field
[0]->value
[0] = 0xf3;
101 report
->field
[0]->value
[1] = 0x00;
102 report
->field
[0]->value
[2] = 0x00;
103 report
->field
[0]->value
[3] = 0x00;
104 report
->field
[0]->value
[4] = 0x00;
105 report
->field
[0]->value
[5] = 0x00;
106 report
->field
[0]->value
[6] = 0x00;
108 usbhid_submit_report(hid
, report
, USB_DIR_OUT
);
110 printk(KERN_INFO
"Force feedback for Logitech Rumblepad 2 by "
111 "Anssi Hannula <anssi.hannula@gmail.com>\n");