From ed19d8cf28b2b03ec05e75de9c1f73981b342978 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 16 Jan 2014 21:43:12 -0500 Subject: HID: sony: Map gyroscopes and accelerometers to axes Use a modified HID descriptor for the Dualshock 4 to assign the gyroscope sensors and accelerometers to axes. Signed-off-by: Frank Praznik Signed-off-by: Jiri Kosina --- drivers/hid/hid-sony.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index a7c81677c540..edffe2c47cf9 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -73,6 +73,73 @@ static const u8 sixaxis_rdesc_fixup2[] = { 0xb1, 0x02, 0xc0, 0xc0, }; +static u8 dualshock4_usb_rdesc[] = { + 0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, + 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, + 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, + 0x04, 0x81, 0x02, 0x09, 0x39, 0x15, 0x00, 0x25, + 0x07, 0x35, 0x00, 0x46, 0x3b, 0x01, 0x65, 0x14, + 0x75, 0x04, 0x95, 0x01, 0x81, 0x42, 0x65, 0x00, + 0x05, 0x09, 0x19, 0x01, 0x29, 0x0e, 0x15, 0x00, + 0x25, 0x01, 0x75, 0x01, 0x95, 0x0e, 0x81, 0x02, + 0x06, 0x00, 0xff, 0x09, 0x20, 0x75, 0x06, 0x95, + 0x01, 0x15, 0x00, 0x25, 0x7f, 0x81, 0x02, 0x05, + 0x01, 0x09, 0x33, 0x09, 0x34, 0x15, 0x00, 0x26, + 0xff, 0x00, 0x75, 0x08, 0x95, 0x02, 0x81, 0x02, + 0x06, 0x00, 0xff, 0x09, 0x21, 0x95, 0x03, 0x81, + 0x02, 0x05, 0x01, 0x19, 0x40, 0x29, 0x42, 0x16, + 0x00, 0x80, 0x26, 0x00, 0x7f, 0x75, 0x10, 0x95, + 0x03, 0x81, 0x02, 0x05, 0x01, 0x19, 0x43, 0x29, + 0x45, 0x16, 0xff, 0xbf, 0x26, 0x00, 0x40, 0x95, + 0x03, 0x81, 0x02, 0x06, 0x00, 0xff, 0x09, 0x21, + 0x75, 0x08, 0x95, 0x27, 0x81, 0x02, 0x85, 0x05, + 0x09, 0x22, 0x95, 0x1f, 0x91, 0x02, 0x85, 0x04, + 0x09, 0x23, 0x95, 0x24, 0xb1, 0x02, 0x85, 0x02, + 0x09, 0x24, 0x95, 0x24, 0xb1, 0x02, 0x85, 0x08, + 0x09, 0x25, 0x95, 0x03, 0xb1, 0x02, 0x85, 0x10, + 0x09, 0x26, 0x95, 0x04, 0xb1, 0x02, 0x85, 0x11, + 0x09, 0x27, 0x95, 0x02, 0xb1, 0x02, 0x85, 0x12, + 0x06, 0x02, 0xff, 0x09, 0x21, 0x95, 0x0f, 0xb1, + 0x02, 0x85, 0x13, 0x09, 0x22, 0x95, 0x16, 0xb1, + 0x02, 0x85, 0x14, 0x06, 0x05, 0xff, 0x09, 0x20, + 0x95, 0x10, 0xb1, 0x02, 0x85, 0x15, 0x09, 0x21, + 0x95, 0x2c, 0xb1, 0x02, 0x06, 0x80, 0xff, 0x85, + 0x80, 0x09, 0x20, 0x95, 0x06, 0xb1, 0x02, 0x85, + 0x81, 0x09, 0x21, 0x95, 0x06, 0xb1, 0x02, 0x85, + 0x82, 0x09, 0x22, 0x95, 0x05, 0xb1, 0x02, 0x85, + 0x83, 0x09, 0x23, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0x84, 0x09, 0x24, 0x95, 0x04, 0xb1, 0x02, 0x85, + 0x85, 0x09, 0x25, 0x95, 0x06, 0xb1, 0x02, 0x85, + 0x86, 0x09, 0x26, 0x95, 0x06, 0xb1, 0x02, 0x85, + 0x87, 0x09, 0x27, 0x95, 0x23, 0xb1, 0x02, 0x85, + 0x88, 0x09, 0x28, 0x95, 0x22, 0xb1, 0x02, 0x85, + 0x89, 0x09, 0x29, 0x95, 0x02, 0xb1, 0x02, 0x85, + 0x90, 0x09, 0x30, 0x95, 0x05, 0xb1, 0x02, 0x85, + 0x91, 0x09, 0x31, 0x95, 0x03, 0xb1, 0x02, 0x85, + 0x92, 0x09, 0x32, 0x95, 0x03, 0xb1, 0x02, 0x85, + 0x93, 0x09, 0x33, 0x95, 0x0c, 0xb1, 0x02, 0x85, + 0xa0, 0x09, 0x40, 0x95, 0x06, 0xb1, 0x02, 0x85, + 0xa1, 0x09, 0x41, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xa2, 0x09, 0x42, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xa3, 0x09, 0x43, 0x95, 0x30, 0xb1, 0x02, 0x85, + 0xa4, 0x09, 0x44, 0x95, 0x0d, 0xb1, 0x02, 0x85, + 0xa5, 0x09, 0x45, 0x95, 0x15, 0xb1, 0x02, 0x85, + 0xa6, 0x09, 0x46, 0x95, 0x15, 0xb1, 0x02, 0x85, + 0xf0, 0x09, 0x47, 0x95, 0x3f, 0xb1, 0x02, 0x85, + 0xf1, 0x09, 0x48, 0x95, 0x3f, 0xb1, 0x02, 0x85, + 0xf2, 0x09, 0x49, 0x95, 0x0f, 0xb1, 0x02, 0x85, + 0xa7, 0x09, 0x4a, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xa8, 0x09, 0x4b, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xa9, 0x09, 0x4c, 0x95, 0x08, 0xb1, 0x02, 0x85, + 0xaa, 0x09, 0x4e, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xab, 0x09, 0x4f, 0x95, 0x39, 0xb1, 0x02, 0x85, + 0xac, 0x09, 0x50, 0x95, 0x39, 0xb1, 0x02, 0x85, + 0xad, 0x09, 0x51, 0x95, 0x0b, 0xb1, 0x02, 0x85, + 0xae, 0x09, 0x52, 0x95, 0x01, 0xb1, 0x02, 0x85, + 0xaf, 0x09, 0x53, 0x95, 0x02, 0xb1, 0x02, 0x85, + 0xb0, 0x09, 0x54, 0x95, 0x3f, 0xb1, 0x02, 0xc0, +}; + static __u8 ps3remote_rdesc[] = { 0x05, 0x01, /* GUsagePage Generic Desktop */ 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ @@ -307,6 +374,17 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, rdesc[55] = 0x06; } + /* + * The default Dualshock 4 USB descriptor doesn't assign + * the gyroscope values to corresponding axes so we need a + * modified one. + */ + if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) { + hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); + rdesc = dualshock4_usb_rdesc; + *rsize = sizeof(dualshock4_usb_rdesc); + } + /* The HID descriptor exposed over BT has a trailing zero byte */ if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) || ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) && -- cgit v1.2.3