2 * Force feedback support for Logitech RumblePad and 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/slab.h>
26 #include <linux/hid.h>
31 struct hid_report *report;
34 static int play_effect(struct input_dev *dev, void *data,
35 struct ff_effect *effect)
37 struct hid_device *hid = input_get_drvdata(dev);
38 struct lg2ff_device *lg2ff = data;
41 strong = effect->u.rumble.strong_magnitude;
42 weak = effect->u.rumble.weak_magnitude;
45 weak = weak * 0xff / 0xffff;
46 strong = strong * 0xff / 0xffff;
48 lg2ff->report->field[0]->value[0] = 0x51;
49 lg2ff->report->field[0]->value[2] = weak;
50 lg2ff->report->field[0]->value[4] = strong;
52 lg2ff->report->field[0]->value[0] = 0xf3;
53 lg2ff->report->field[0]->value[2] = 0x00;
54 lg2ff->report->field[0]->value[4] = 0x00;
57 hid_hw_request(hid, lg2ff->report, HID_REQ_SET_REPORT);
61 int lg2ff_init(struct hid_device *hid)
63 struct lg2ff_device *lg2ff;
64 struct hid_report *report;
65 struct hid_input *hidinput;
66 struct input_dev *dev;
69 if (list_empty(&hid->inputs)) {
70 hid_err(hid, "no inputs found\n");
73 hidinput = list_entry(hid->inputs.next, struct hid_input, list);
74 dev = hidinput->input;
76 /* Check that the report looks ok */
77 report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7);
81 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
85 set_bit(FF_RUMBLE, dev->ffbit);
87 error = input_ff_create_memless(dev, lg2ff, play_effect);
93 lg2ff->report = report;
94 report->field[0]->value[0] = 0xf3;
95 report->field[0]->value[1] = 0x00;
96 report->field[0]->value[2] = 0x00;
97 report->field[0]->value[3] = 0x00;
98 report->field[0]->value[4] = 0x00;
99 report->field[0]->value[5] = 0x00;
100 report->field[0]->value[6] = 0x00;
102 hid_hw_request(hid, report, HID_REQ_SET_REPORT);
104 hid_info(hid, "Force feedback for Logitech variant 2 rumble devices by Anssi Hannula <anssi.hannula@gmail.com>\n");