Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  HID driver for Redragon keyboards
0003  *
0004  *  Copyright (c) 2017 Robert Munteanu
0005  *  SPDX-License-Identifier: GPL-2.0+
0006  */
0007 
0008 /*
0009  * This program is free software; you can redistribute it and/or modify it
0010  * under the terms of the GNU General Public License as published by the Free
0011  * Software Foundation; either version 2 of the License, or (at your option)
0012  * any later version.
0013  */
0014 
0015 #include <linux/device.h>
0016 #include <linux/hid.h>
0017 #include <linux/module.h>
0018 
0019 #include "hid-ids.h"
0020 
0021 
0022 /*
0023  * The Redragon Asura keyboard sends an incorrect HID descriptor.
0024  * At byte 100 it contains
0025  *
0026  *   0x81, 0x00
0027  *
0028  * which is Input (Data, Arr, Abs), but it should be
0029  *
0030  *   0x81, 0x02
0031  *
0032  * which is Input (Data, Var, Abs), which is consistent with the way
0033  * key codes are generated.
0034  */
0035 
0036 static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
0037     unsigned int *rsize)
0038 {
0039     if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
0040         dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
0041         rdesc[101] = 0x02;
0042     }
0043 
0044     return rdesc;
0045 }
0046 
0047 static const struct hid_device_id redragon_devices[] = {
0048     {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
0049     {}
0050 };
0051 
0052 MODULE_DEVICE_TABLE(hid, redragon_devices);
0053 
0054 static struct hid_driver redragon_driver = {
0055     .name = "redragon",
0056     .id_table = redragon_devices,
0057     .report_fixup = redragon_report_fixup
0058 };
0059 
0060 module_hid_driver(redragon_driver);
0061 
0062 MODULE_LICENSE("GPL");