diff mbox

[RFC,v2,HID] allow using external Hid Descriptors.

Message ID 4B337226.6050509@gmail.com (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Marcin Tolysz Dec. 24, 2009, 1:52 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 80792d3..4ee4299 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -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>
@@ -640,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,
@@ -650,10 +655,28 @@  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 */
+	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;
 
@@ -690,6 +713,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;
 		}
@@ -697,6 +722,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;
 }