From: Jiri Kosina <jkosina@suse.cz>

HID: add support for Genius Ergo Mouse

This device sends several buttons in a separate field, which is
wrongly described in the report descriptor. Fix it in the following
way:

- change led usage page to button
- report size 8 count 1 becomes report size 1 count 8
- the button usage range changed to 4-7 (the mouse has three buttons in
  a different field already).

Signed-off-by: Jiri Kosina <jkosina@suse.cz>

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index e85c8fe..2baf213 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -135,6 +135,13 @@ config HID_EZKEY
 	---help---
 	Support for Ezkey BTC 8193 keyboard.
 
+config HID_GENIUS
+	tristate "Genius" if EMBEDDED
+	depends on USB_HID
+	default !EMBEDDED
+	---help---
+	Support for Genius Ergo Mouse.
+
 config HID_GYRATION
 	tristate "Gyration" if EMBEDDED
 	depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index fbd021f..93a2461 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_HID_CHERRY)	+= hid-cherry.o
 obj-$(CONFIG_HID_CHICONY)	+= hid-chicony.o
 obj-$(CONFIG_HID_CYPRESS)	+= hid-cypress.o
 obj-$(CONFIG_HID_EZKEY)		+= hid-ezkey.o
+obj-$(CONFIG_HID_GENIUS)	+= hid-genius.o
 obj-$(CONFIG_HID_GYRATION)	+= hid-gyration.o
 obj-$(CONFIG_HID_LOGITECH)	+= hid-logitech.o
 obj-$(CONFIG_HID_MICROSOFT)	+= hid-microsoft.o
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 1cc9674..ee9c1a9 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1267,6 +1267,7 @@ static const struct hid_device_id hid_blacklist[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_GENIUS, USB_DEVICE_ID_GENIUS_ERGO_MOUSE) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
diff --git a/drivers/hid/hid-dummy.c b/drivers/hid/hid-dummy.c
index b4cc0f7..0ba2c7a 100644
--- a/drivers/hid/hid-dummy.c
+++ b/drivers/hid/hid-dummy.c
@@ -31,6 +31,9 @@ static int __init hid_dummy_init(void)
 #ifdef CONFIG_HID_EZKEY_MODULE
 	HID_COMPAT_CALL_DRIVER(ezkey);
 #endif
+#ifdef CONFIG_HID_GENIUS_MODULE
+	HID_COMPAT_CALL_DRIVER(genius);
+#endif
 #ifdef CONFIG_HID_GYRATION_MODULE
 	HID_COMPAT_CALL_DRIVER(gyration);
 #endif
diff --git a/drivers/hid/hid-genius.c b/drivers/hid/hid-genius.c
new file mode 100644
index 0000000..08f1cfc
--- /dev/null
+++ b/drivers/hid/hid-genius.c
@@ -0,0 +1,65 @@
+/*
+ *  HID driver for Genius Ergo Mouse
+ *
+ *  Copyright (c) 2009 Jiri Kosina
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+
+#include "hid-ids.h"
+
+static void genius_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+		unsigned int rsize)
+{
+	if (rsize >= 74 &&
+		rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
+		rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
+		rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
+		rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
+		rdesc[73] == 0x95 && rdesc[74] == 0x01) {
+		dev_info(&hdev->dev, "fixing up Genius Ergo Mouse report "
+				"descriptor\n");
+		rdesc[62] = 0x09;
+		rdesc[64] = 0x04;
+		rdesc[66] = 0x07;
+		rdesc[72] = 0x01;
+		rdesc[74] = 0x08;
+	}
+}
+
+static const struct hid_device_id genius_devices[] = {
+	{ HID_USB_DEVICE(USB_VENDOR_ID_GENIUS, USB_DEVICE_ID_GENIUS_ERGO_MOUSE) },
+	{ }
+};
+MODULE_DEVICE_TABLE(hid, genius_devices);
+
+static struct hid_driver genius_driver = {
+	.name = "genius",
+	.id_table = genius_devices,
+	.report_fixup = genius_report_fixup,
+};
+
+static int genius_init(void)
+{
+	return hid_register_driver(&genius_driver);
+}
+
+static void genius_exit(void)
+{
+	hid_unregister_driver(&genius_driver);
+}
+
+module_init(genius_init);
+module_exit(genius_exit);
+MODULE_LICENSE("GPL");
+
+HID_COMPAT_LOAD_DRIVER(genius);
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 8851197..f291914 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -163,6 +163,9 @@
 
 #define USB_VENDOR_ID_GENERAL_TOUCH	0x0dfc
 
+#define USB_VENDOR_ID_GENIUS		0x0458
+#define USB_DEVICE_ID_GENIUS_ERGO_MOUSE	0x0087
+
 #define USB_VENDOR_ID_GLAB		0x06c2
 #define USB_DEVICE_ID_4_PHIDGETSERVO_30	0x0038
 #define USB_DEVICE_ID_1_PHIDGETSERVO_30	0x0039
