diff options
author | Sven Eckelmann <sven@narfation.org> | 2013-11-09 18:25:57 (GMT) |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-11-11 10:25:46 (GMT) |
commit | a08c22c0df0ad23d0df10ae1a9df26643589b3cc (patch) | |
tree | 476d2fe040e9337b70f73587c56f27890059ae08 /drivers/hid/hid-sony.c | |
parent | ae2aa3a512fa5f50f67feba9e66bc2efb394bd63 (diff) | |
download | linux-a08c22c0df0ad23d0df10ae1a9df26643589b3cc.tar.xz |
HID: sony: Add force feedback support for Dualshock3 USB
Sony Dualshock 3 controllers have two motors which can be used to provide
simple force feedback rumble effects. The right motor is can be used to create
a weak rumble effect but does not allow to set the force. The left motor is
used to create a strong rumble effect with adjustable intensity.
The state of both motors can be changed using HID_OUTPUT_REPORT packets and
have no timing information. FF memless is used to keep track of the timing and
the sony driver just generates the necessary URBs.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-sony.c')
-rw-r--r-- | drivers/hid/hid-sony.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index bc37a18..da551d1 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -614,6 +614,54 @@ static void buzz_remove(struct hid_device *hdev) drv_data->extra = NULL; } +#ifdef CONFIG_SONY_FF +static int sony_play_effect(struct input_dev *dev, void *data, + struct ff_effect *effect) +{ + unsigned char buf[] = { + 0x01, + 0x00, 0xff, 0x00, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0x00, 0x00, 0x00, 0x00, 0x00 + }; + __u8 left; + __u8 right; + struct hid_device *hid = input_get_drvdata(dev); + + if (effect->type != FF_RUMBLE) + return 0; + + left = effect->u.rumble.strong_magnitude / 256; + right = effect->u.rumble.weak_magnitude ? 1 : 0; + + buf[3] = right; + buf[5] = left; + + return hid->hid_output_raw_report(hid, buf, sizeof(buf), + HID_OUTPUT_REPORT); +} + +static int sony_init_ff(struct hid_device *hdev) +{ + struct hid_input *hidinput = list_entry(hdev->inputs.next, + struct hid_input, list); + struct input_dev *input_dev = hidinput->input; + + input_set_capability(input_dev, EV_FF, FF_RUMBLE); + return input_ff_create_memless(input_dev, NULL, sony_play_effect); +} + +#else +static int sony_init_ff(struct hid_device *hdev) +{ + return 0; +} +#endif + static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret; @@ -663,6 +711,10 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) if (ret < 0) goto err_stop; + ret = sony_init_ff(hdev); + if (ret < 0) + goto err_stop; + return 0; err_stop: hid_hw_stop(hdev); |