Merge tag 'mvebu-fixes-4.17-2' of git://git.infradead.org/linux-mvebu into fixes
[sfrench/cifs-2.6.git] / drivers / hid / hid-redragon.c
1 /*
2  *  HID driver for Redragon keyboards
3  *
4  *  Copyright (c) 2017 Robert Munteanu
5  *  SPDX-License-Identifier: GPL-2.0+
6  */
7
8 /*
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the Free
11  * Software Foundation; either version 2 of the License, or (at your option)
12  * any later version.
13  */
14
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18
19 #include "hid-ids.h"
20
21
22 /*
23  * The Redragon Asura keyboard sends an incorrect HID descriptor.
24  * At byte 100 it contains
25  *
26  *   0x81, 0x00
27  *
28  * which is Input (Data, Arr, Abs), but it should be
29  *
30  *   0x81, 0x02
31  *
32  * which is Input (Data, Var, Abs), which is consistent with the way
33  * key codes are generated.
34  */
35
36 static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
37         unsigned int *rsize)
38 {
39         if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
40                 dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
41                 rdesc[101] = 0x02;
42         }
43
44         return rdesc;
45 }
46
47 static int redragon_probe(struct hid_device *dev,
48         const struct hid_device_id *id)
49 {
50         int ret;
51
52         ret = hid_parse(dev);
53         if (ret) {
54                 hid_err(dev, "parse failed\n");
55                 return ret;
56         }
57
58         /* do not register unused input device */
59         if (dev->maxapplication == 1)
60                 return 0;
61
62         ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
63         if (ret) {
64                 hid_err(dev, "hw start failed\n");
65                 return ret;
66         }
67
68         return 0;
69 }
70 static const struct hid_device_id redragon_devices[] = {
71         {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
72         {}
73 };
74
75 MODULE_DEVICE_TABLE(hid, redragon_devices);
76
77 static struct hid_driver redragon_driver = {
78         .name = "redragon",
79         .id_table = redragon_devices,
80         .report_fixup = redragon_report_fixup,
81         .probe = redragon_probe
82 };
83
84 module_hid_driver(redragon_driver);
85
86 MODULE_LICENSE("GPL");