HID: hid-sony: fix endiannes of Sixaxis accel/gyro values
authorSimon Wood <simon@mungewell.org>
Fri, 10 Jun 2011 10:00:27 +0000 (12:00 +0200)
committerJiri Kosina <jkosina@suse.cz>
Mon, 13 Jun 2011 11:21:30 +0000 (13:21 +0200)
The accelerometers/gyro on the Sixaxis are reported in the wrong
endianness (ie. not compatible with HID), so this patch intercepts
the report and swaps the appropriate bytes over.

Accelerometers are scaled with a nominal value of +/-4000 = 1G,
maximum value would be around +/-32768 = 8G.

Gyro on my device always reports -32768, might need some calibration
set within the controller.

Fix extracted from previous patch submission:
https://patchwork.kernel.org/patch/95212/

Signed-off-by: Marcin Tolysz <tolysz@gmail.com>
Signed-off-by: Simon Wood <simon@mungewell.org>
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-sony.c

index 5398507..5cd25bd 100644 (file)
@@ -61,6 +61,25 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
        return rdesc;
 }
 
+static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
+               __u8 *rd, int size)
+{
+       struct sony_sc *sc = hid_get_drvdata(hdev);
+
+       /* Sixaxis HID report has acclerometers/gyro with MSByte first, this
+        * has to be BYTE_SWAPPED before passing up to joystick interface
+        */
+       if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) &&
+                       rd[0] == 0x01 && size == 49) {
+               swap(rd[41], rd[42]);
+               swap(rd[43], rd[44]);
+               swap(rd[45], rd[46]);
+               swap(rd[47], rd[48]);
+       }
+
+       return 0;
+}
+
 /*
  * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP
  * like it should according to usbhid/hid-core.c::usbhid_output_raw_report()
@@ -209,6 +228,7 @@ static struct hid_driver sony_driver = {
        .probe = sony_probe,
        .remove = sony_remove,
        .report_fixup = sony_report_fixup,
+       .raw_event = sony_raw_event
 };
 
 static int __init sony_init(void)