@@ -27,6 +27,7 @@
#include <linux/wait.h>
#include <linux/vmalloc.h>
#include <linux/sched.h>
+#include <linux/firmware.h>
#include <linux/hid.h>
#include <linux/hiddev.h>
@@ -333,10 +334,8 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
return 0;
case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
- if (parser->global.physical_minimum < 0)
- parser->global.physical_maximum = item_sdata(item);
- else
- parser->global.physical_maximum = item_udata(item);
+ /* always signed value, if it is less then minimum we need to invert axis */
+ parser->global.physical_maximum = item_sdata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
@@ -642,6 +641,10 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
struct hid_item item;
__u8 *end;
int ret;
+ const struct firmware *fw;
+ int fw_fail;
+ const char *file;
+
static int (*dispatch_type[])(struct hid_parser *parser,
struct hid_item *item) = {
hid_parser_main,
@@ -652,10 +655,39 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
if (device->driver->report_fixup)
device->driver->report_fixup(device, start, size);
+ /* Now try to load a hid descriptor from a file firmware
+ if succesful ignoring this fixup thing */
+ /*
+ Mini howto: fixing the descriptor:
+ 1) dump it from /debug/hid/!!device!!/rdesc
+ 2) copy 1st line &edit it
+ 3) convert to bin eg. cat descriptor.txt | hex2bin.sh > descriptor.bin
+
+----hex2bin.sh
+#!/bin/bash
+echo -n -e $(tr -d '[:space:]' | sed 's/../\\x&/g')
+4) place in /lib/firmware/hid/... where the location is provided by kern.log
+*/
+ file = kasprintf(GFP_KERNEL, "hid/%04X:%04X:%04X:%04X.bin",
+ device->bus, device->vendor, device->product, device->version);
+
+ fw_fail = request_firmware(&fw, file, &device->dev);
+
+ if (fw_fail)
+ pr_info("To relace HID descriptor place it in /lib/firmaware/%s\n", file);
+ else{
+ start = fw->data;
+ size = fw->size;
+ pr_info("HID descriptor relaced with /lib/firmaware/%s\n", file);
+ }
+ kfree(file);
device->rdesc = kmalloc(size, GFP_KERNEL);
- if (device->rdesc == NULL)
+ if (device->rdesc == NULL) {
+ if (!fw_fail)
+ release_firmware(fw);
return -ENOMEM;
+ }
memcpy(device->rdesc, start, size);
device->rsize = size;
@@ -692,6 +724,8 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
dbg_hid("unbalanced delimiter at end of report description\n");
goto err;
}
+ if (!fw_fail)
+ release_firmware(fw);
vfree(parser);
return 0;
}
@@ -699,6 +733,8 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
err:
+ if (!fw_fail)
+ release_firmware(fw);
vfree(parser);
return ret;
}
@@ -878,6 +914,25 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field,
}
/*
+ * Translate values from logical to physical, exponent is still missing.
+ */
+static __s32 convert_to_physical(__s32 x, struct hid_field *field)
+{
+ __s32 min = field->logical_minimum;
+ __s32 max = field->logical_maximum;
+ __s32 pmin = field->physical_minimum;
+ __s32 pmax = field->physical_maximum;
+/* __s32 uexp = field->unit_exponent; need to find a way how to use it */
+
+ if ((pmin == pmax) /* would give pmin and covers the case ==0 */
+ || (pmin == min && pmax == max) /* would do nothing */
+ || (min == max)) /* would be div by 0 */
+ return x;
+ else
+ return (pmax - pmin)*(x - min) / (max - min) + pmin;
+}
+
+/*
* Analyse a received field, and fetch the data from it. The field
* content is stored for next report processing (we do differential
* reporting to the layer).
@@ -911,7 +966,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
for (n = 0; n < count; n++) {
if (HID_MAIN_ITEM_VARIABLE & field->flags) {
- hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
+ hid_process_event(hid, field, &field->usage[n], convert_to_physical(value[n], field), interrupt);
continue;
}
@@ -45,6 +45,24 @@ static void sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
}
/*
+ * There is a few bits that has to be shifted around to make this report more compatibile with
+ * HID standard descriptions, and we want it to be parsable by standard driver
+ */
+static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, __u8 *rd, int size)
+{
+ /* for sixaxis connected via usb. */
+ if (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;
+}
+
+
+/*
* Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
* to "operational". Without this, the ps3 controller will not report any
* events.
@@ -151,6 +169,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)