File: hid-topre.c

package info (click to toggle)
linux 6.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,532,052 kB
  • sloc: ansic: 23,400,063; asm: 266,720; sh: 108,896; makefile: 49,712; python: 36,925; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (49 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: GPL-2.0+
/*
 *  HID driver for Topre REALFORCE Keyboards
 *
 *  Copyright (c) 2022 Harry Stern <harry@harrystern.net>
 *
 *  Based on the hid-macally driver
 */

#include <linux/hid.h>
#include <linux/module.h>

#include "hid-ids.h"

MODULE_AUTHOR("Harry Stern <harry@harrystern.net>");
MODULE_DESCRIPTION("REALFORCE R2 Keyboard driver");
MODULE_LICENSE("GPL");

/*
 * Fix the REALFORCE R2's non-boot interface's report descriptor to match the
 * events it's actually sending. It claims to send array events but is instead
 * sending variable events.
 */
static __u8 *topre_report_fixup(struct hid_device *hdev, __u8 *rdesc,
				 unsigned int *rsize)
{
	if (*rsize >= 119 && rdesc[69] == 0x29 && rdesc[70] == 0xe7 &&
						 rdesc[71] == 0x81 && rdesc[72] == 0x00) {
		hid_info(hdev,
			"fixing up Topre REALFORCE keyboard report descriptor\n");
		rdesc[72] = 0x02;
	}
	return rdesc;
}

static const struct hid_device_id topre_id_table[] = {
	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
			 USB_DEVICE_ID_TOPRE_REALFORCE_R2_108) },
	{ }
};
MODULE_DEVICE_TABLE(hid, topre_id_table);

static struct hid_driver topre_driver = {
	.name			= "topre",
	.id_table		= topre_id_table,
	.report_fixup		= topre_report_fixup,
};

module_hid_driver(topre_driver);