xref: /openbmc/linux/drivers/hid/hid-topre.c (revision 2f164822)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  HID driver for Topre REALFORCE Keyboards
4  *
5  *  Copyright (c) 2022 Harry Stern <harry@harrystern.net>
6  *
7  *  Based on the hid-macally driver
8  */
9 
10 #include <linux/hid.h>
11 #include <linux/module.h>
12 
13 #include "hid-ids.h"
14 
15 MODULE_AUTHOR("Harry Stern <harry@harrystern.net>");
16 MODULE_DESCRIPTION("REALFORCE R2 Keyboard driver");
17 MODULE_LICENSE("GPL");
18 
19 /*
20  * Fix the REALFORCE R2's non-boot interface's report descriptor to match the
21  * events it's actually sending. It claims to send array events but is instead
22  * sending variable events.
23  */
24 static __u8 *topre_report_fixup(struct hid_device *hdev, __u8 *rdesc,
25 				 unsigned int *rsize)
26 {
27 	if (*rsize >= 119 && rdesc[69] == 0x29 && rdesc[70] == 0xe7 &&
28 						 rdesc[71] == 0x81 && rdesc[72] == 0x00) {
29 		hid_info(hdev,
30 			"fixing up Topre REALFORCE keyboard report descriptor\n");
31 		rdesc[72] = 0x02;
32 	}
33 	return rdesc;
34 }
35 
36 static const struct hid_device_id topre_id_table[] = {
37 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
38 			 USB_DEVICE_ID_TOPRE_REALFORCE_R2_108) },
39 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
40 			 USB_DEVICE_ID_TOPRE_REALFORCE_R2_87) },
41 	{ }
42 };
43 MODULE_DEVICE_TABLE(hid, topre_id_table);
44 
45 static struct hid_driver topre_driver = {
46 	.name			= "topre",
47 	.id_table		= topre_id_table,
48 	.report_fixup		= topre_report_fixup,
49 };
50 
51 module_hid_driver(topre_driver);
52