HID: redragon: Fix modifier keys for Redragon Asura Keyboard
authorRobert Munteanu <rombert@apache.org>
Mon, 16 Apr 2018 21:38:24 +0000 (00:38 +0300)
committerJiri Kosina <jkosina@suse.cz>
Tue, 17 Apr 2018 11:56:29 +0000 (13:56 +0200)
This adds a new driver for the Redragon Asura keyboard. The Asura
keyboard contains an error in the HID descriptor which causes all
modifier keys to be mapped to left shift. Additionally, we suppress
the creation of a second, not working, keyboard device.

Signed-off-by: Robert Munteanu <rombert@apache.org>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/Kconfig
drivers/hid/Makefile
drivers/hid/hid-ids.h
drivers/hid/hid-redragon.c [new file with mode: 0644]

index 60252fd796f6a86513b577f7b05cb3123ddeec81..c486bae2d53244001366ab2b66676d5f9bae5d4e 100644 (file)
@@ -574,6 +574,13 @@ config HID_MAYFLASH
        Say Y here if you have HJZ Mayflash PS3 game controller adapters
        and want to enable force feedback support.
 
+config HID_REDRAGON
+       tristate "Redragon keyboards"
+       depends on HID
+       default !EXPERT
+       ---help---
+    Support for Redragon keyboards that need fix-ups to work properly.
+
 config HID_MICROSOFT
        tristate "Microsoft non-fully HID-compliant devices"
        depends on HID
index 17a8bd97da9dc29ad7146e79d12bcfcade911d7e..3283c79b50a885341116e4e5bf3d48908eadbb3d 100644 (file)
@@ -86,6 +86,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)                += hid-picolcd_debugfs.o
 
 obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
 obj-$(CONFIG_HID_PRIMAX)       += hid-primax.o
+obj-$(CONFIG_HID_REDRAGON)     += hid-redragon.o
 obj-$(CONFIG_HID_RETRODE)      += hid-retrode.o
 obj-$(CONFIG_HID_ROCCAT)       += hid-roccat.o hid-roccat-common.o \
        hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
index 5a3a7ead301214dceb5cbe99308a08160515ae89..07e31461690b363d022fe62ae9fff6dc43aeaea1 100644 (file)
 #define USB_VENDOR_ID_JESS             0x0c45
 #define USB_DEVICE_ID_JESS_YUREX       0x1010
 #define USB_DEVICE_ID_ASUS_MD_5112     0x5112
+#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
 
 #define USB_VENDOR_ID_JESS2            0x0f30
 #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
new file mode 100644 (file)
index 0000000..daf5957
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  HID driver for Redragon keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ *  SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * 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"
+
+
+/*
+ * The Redragon Asura keyboard sends an incorrect HID descriptor.
+ * At byte 100 it contains
+ *
+ *   0x81, 0x00
+ *
+ * which is Input (Data, Arr, Abs), but it should be
+ *
+ *   0x81, 0x02
+ *
+ * which is Input (Data, Var, Abs), which is consistent with the way
+ * key codes are generated.
+ */
+
+static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+       unsigned int *rsize)
+{
+       if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
+               dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
+               rdesc[101] = 0x02;
+       }
+
+       return rdesc;
+}
+
+static int redragon_probe(struct hid_device *dev,
+       const struct hid_device_id *id)
+{
+       int ret;
+
+       ret = hid_parse(dev);
+       if (ret) {
+               hid_err(dev, "parse failed\n");
+               return ret;
+       }
+
+       /* do not register unused input device */
+       if (dev->maxapplication == 1)
+               return 0;
+
+       ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
+       if (ret) {
+               hid_err(dev, "hw start failed\n");
+               return ret;
+       }
+
+       return 0;
+}
+static const struct hid_device_id redragon_devices[] = {
+       {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
+       {}
+};
+
+MODULE_DEVICE_TABLE(hid, redragon_devices);
+
+static struct hid_driver redragon_driver = {
+       .name = "redragon",
+       .id_table = redragon_devices,
+       .report_fixup = redragon_report_fixup,
+       .probe = redragon_probe
+};
+
+module_hid_driver(redragon_driver);
+
+MODULE_LICENSE("GPL");