blob: 128f0117c7a76318d6cf211973c5a97dc0f0a139 [file] [log] [blame]
Anssi Hannulac17f9c92008-04-01 01:51:11 +02001/*
Hendrik Iben2c6118e2010-10-04 15:39:49 +02002 * Force feedback support for Logitech RumblePad and Rumblepad 2
Anssi Hannulac17f9c92008-04-01 01:51:11 +02003 *
4 * Copyright (c) 2008 Anssi Hannula <anssi.hannula@gmail.com>
5 */
6
7/*
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.
12 *
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.
17 *
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
21 */
22
23
24#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Anssi Hannulac17f9c92008-04-01 01:51:11 +020026#include <linux/usb.h>
27#include <linux/hid.h>
Jiri Slaby606bd0a2008-07-04 23:06:45 +020028
29#include "usbhid/usbhid.h"
30#include "hid-lg.h"
Anssi Hannulac17f9c92008-04-01 01:51:11 +020031
32struct lg2ff_device {
33 struct hid_report *report;
34};
35
36static int play_effect(struct input_dev *dev, void *data,
37 struct ff_effect *effect)
38{
39 struct hid_device *hid = input_get_drvdata(dev);
40 struct lg2ff_device *lg2ff = data;
41 int weak, strong;
42
43 strong = effect->u.rumble.strong_magnitude;
44 weak = effect->u.rumble.weak_magnitude;
45
46 if (weak || strong) {
47 weak = weak * 0xff / 0xffff;
48 strong = strong * 0xff / 0xffff;
49
50 lg2ff->report->field[0]->value[0] = 0x51;
51 lg2ff->report->field[0]->value[2] = weak;
52 lg2ff->report->field[0]->value[4] = strong;
53 } else {
54 lg2ff->report->field[0]->value[0] = 0xf3;
55 lg2ff->report->field[0]->value[2] = 0x00;
56 lg2ff->report->field[0]->value[4] = 0x00;
57 }
58
59 usbhid_submit_report(hid, lg2ff->report, USB_DIR_OUT);
60 return 0;
61}
62
Jiri Slaby606bd0a2008-07-04 23:06:45 +020063int lg2ff_init(struct hid_device *hid)
Anssi Hannulac17f9c92008-04-01 01:51:11 +020064{
65 struct lg2ff_device *lg2ff;
66 struct hid_report *report;
67 struct hid_input *hidinput = list_entry(hid->inputs.next,
68 struct hid_input, list);
Anssi Hannulac17f9c92008-04-01 01:51:11 +020069 struct input_dev *dev = hidinput->input;
70 int error;
71
Kees Cooke7529c32013-09-11 21:56:54 +020072 /* Check that the report looks ok */
73 report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7);
74 if (!report)
Anssi Hannulac17f9c92008-04-01 01:51:11 +020075 return -ENODEV;
Anssi Hannulac17f9c92008-04-01 01:51:11 +020076
77 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
78 if (!lg2ff)
79 return -ENOMEM;
80
81 set_bit(FF_RUMBLE, dev->ffbit);
82
83 error = input_ff_create_memless(dev, lg2ff, play_effect);
84 if (error) {
85 kfree(lg2ff);
86 return error;
87 }
88
89 lg2ff->report = report;
90 report->field[0]->value[0] = 0xf3;
91 report->field[0]->value[1] = 0x00;
92 report->field[0]->value[2] = 0x00;
93 report->field[0]->value[3] = 0x00;
94 report->field[0]->value[4] = 0x00;
95 report->field[0]->value[5] = 0x00;
96 report->field[0]->value[6] = 0x00;
97
98 usbhid_submit_report(hid, report, USB_DIR_OUT);
99
Joe Perches4291ee32010-12-09 19:29:03 -0800100 hid_info(hid, "Force feedback for Logitech RumblePad/Rumblepad 2 by Anssi Hannula <anssi.hannula@gmail.com>\n");
Anssi Hannulac17f9c92008-04-01 01:51:11 +0200101
102 return 0;
103}