| 1 | |
| 2 | |
| 3 | * HID driver for ELECOM devices:
|
| 4 | * - BM084 Bluetooth Mouse
|
| 5 | * - EX-G Trackballs (M-XT3DRBK, M-XT3URBK, M-XT4DRBK)
|
| 6 | * - DEFT Trackballs (M-DT1DRBK, M-DT1URBK, M-DT2DRBK, M-DT2URBK)
|
| 7 | * - HUGE Trackballs (M-HT1DRBK, M-HT1URBK)
|
| 8 | * - HUGE Plus Trackball (M-HT1MRBK)
|
| 9 | *
|
| 10 | * Copyright (c) 2010 Richard Nauber <[email protected]>
|
| 11 | * Copyright (c) 2016 Yuxuan Shui <[email protected]>
|
| 12 | * Copyright (c) 2017 Diego Elio Pettenò <[email protected]>
|
| 13 | * Copyright (c) 2017 Alex Manoussakis <[email protected]>
|
| 14 | * Copyright (c) 2017 Tomasz Kramkowski <[email protected]>
|
| 15 | * Copyright (c) 2020 YOSHIOKA Takuma <[email protected]>
|
| 16 | * Copyright (c) 2022 Takahiro Fujii <[email protected]>
|
| 17 |
|
| 18 |
|
| 19 | |
| 20 |
|
| 21 |
|
| 22 | #include <linux/device.h>
|
| 23 | #include <linux/hid.h>
|
| 24 | #include <linux/module.h>
|
| 25 |
|
| 26 | #include "hid-ids.h"
|
| 27 |
|
| 28 | |
| 29 | * Certain ELECOM mice misreport their button count meaning that they only work
|
| 30 | * correctly with the ELECOM mouse assistant software which is unavailable for
|
| 31 | * Linux. A four extra INPUT reports and a FEATURE report are described by the
|
| 32 | * report descriptor but it does not appear that these enable software to
|
| 33 | * control what the extra buttons map to. The only simple and straightforward
|
| 34 | * solution seems to involve fixing up the report descriptor.
|
| 35 |
|
| 36 | #define MOUSE_BUTTONS_MAX 8
|
| 37 | static void mouse_button_fixup(struct hid_device *hdev,
|
| 38 | __u8 *rdesc, unsigned int rsize,
|
| 39 | unsigned int button_bit_count,
|
| 40 | unsigned int padding_bit,
|
| 41 | unsigned int button_report_size,
|
| 42 | unsigned int button_usage_maximum,
|
| 43 | int nbuttons)
|
| 44 | {
|
| 45 | if (rsize < 32 || rdesc[button_bit_count] != 0x95 ||
|
| 46 | rdesc[button_report_size] != 0x75 ||
|
| 47 | rdesc[button_report_size + 1] != 0x01 ||
|
| 48 | rdesc[button_usage_maximum] != 0x29 || rdesc[padding_bit] != 0x75)
|
| 49 | return;
|
| 50 | hid_info(hdev, "Fixing up Elecom mouse button count\n");
|
| 51 | nbuttons = clamp(nbuttons, 0, MOUSE_BUTTONS_MAX);
|
| 52 | rdesc[button_bit_count + 1] = nbuttons;
|
| 53 | rdesc[button_usage_maximum + 1] = nbuttons;
|
| 54 | rdesc[padding_bit + 1] = MOUSE_BUTTONS_MAX - nbuttons;
|
| 55 | }
|
| 56 |
|
| 57 | static const __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
| 58 | unsigned int *rsize)
|
| 59 | {
|
| 60 | switch (hdev->product) {
|
| 61 | case USB_DEVICE_ID_ELECOM_BM084:
|
| 62 | |
| 63 | * wheel in the HID descriptor.
|
| 64 | if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) {
|
| 65 | hid_info(hdev, "Fixing up Elecom BM084 report descriptor\n");
|
| 66 | rdesc[47] = 0x00;
|
| 67 | }
|
| 68 | break;
|
| 69 | case USB_DEVICE_ID_ELECOM_M_XGL20DLBK:
|
| 70 | |
| 71 | * Report descriptor format:
|
| 72 | * 20: button bit count
|
| 73 | * 28: padding bit count
|
| 74 | * 22: button report size
|
| 75 | * 14: button usage maximum
|
| 76 |
|
| 77 | mouse_button_fixup(hdev, rdesc, *rsize, 20, 28, 22, 14, 8);
|
| 78 | break;
|
| 79 | case USB_DEVICE_ID_ELECOM_M_XT3URBK_00FB:
|
| 80 | case USB_DEVICE_ID_ELECOM_M_XT3URBK_018F:
|
| 81 | case USB_DEVICE_ID_ELECOM_M_XT3DRBK_00FC:
|
| 82 | case USB_DEVICE_ID_ELECOM_M_XT4DRBK_00FD:
|
| 83 | |
| 84 | * Report descriptor format:
|
| 85 | * 12: button bit count
|
| 86 | * 30: padding bit count
|
| 87 | * 14: button report size
|
| 88 | * 20: button usage maximum
|
| 89 |
|
| 90 | mouse_button_fixup(hdev, rdesc, *rsize, 12, 30, 14, 20, 6);
|
| 91 | break;
|
| 92 | case USB_DEVICE_ID_ELECOM_M_DT1URBK:
|
| 93 | case USB_DEVICE_ID_ELECOM_M_DT1DRBK:
|
| 94 | case USB_DEVICE_ID_ELECOM_M_HT1URBK_010C:
|
| 95 | case USB_DEVICE_ID_ELECOM_M_HT1URBK_019B:
|
| 96 | case USB_DEVICE_ID_ELECOM_M_HT1DRBK_010D:
|
| 97 | |
| 98 | * Report descriptor format:
|
| 99 | * 12: button bit count
|
| 100 | * 30: padding bit count
|
| 101 | * 14: button report size
|
| 102 | * 20: button usage maximum
|
| 103 |
|
| 104 | mouse_button_fixup(hdev, rdesc, *rsize, 12, 30, 14, 20, 8);
|
| 105 | break;
|
| 106 | case USB_DEVICE_ID_ELECOM_M_XT3DRBK_018C:
|
| 107 | case USB_DEVICE_ID_ELECOM_M_XT4DRBK_018E:
|
| 108 | |
| 109 | * Report descriptor format:
|
| 110 | * 22: button bit count
|
| 111 | * 30: padding bit count
|
| 112 | * 24: button report size
|
| 113 | * 16: button usage maximum
|
| 114 |
|
| 115 | mouse_button_fixup(hdev, rdesc, *rsize, 22, 30, 24, 16, 6);
|
| 116 | break;
|
| 117 | case USB_DEVICE_ID_ELECOM_M_DT2DRBK:
|
| 118 | case USB_DEVICE_ID_ELECOM_M_HT1DRBK_011C:
|
| 119 | |
| 120 | * Report descriptor format:
|
| 121 | * 22: button bit count
|
| 122 | * 30: padding bit count
|
| 123 | * 24: button report size
|
| 124 | * 16: button usage maximum
|
| 125 |
|
| 126 | mouse_button_fixup(hdev, rdesc, *rsize, 22, 30, 24, 16, 8);
|
| 127 | break;
|
| 128 | case USB_DEVICE_ID_ELECOM_M_HT1MRBK:
|
| 129 | case USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AB:
|
| 130 | case USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AC:
|
| 131 | |
| 132 | * Report descriptor format:
|
| 133 | * 24: button bit count
|
| 134 | * 28: padding bit count
|
| 135 | * 22: button report size
|
| 136 | * 16: button usage maximum
|
| 137 |
|
| 138 | mouse_button_fixup(hdev, rdesc, *rsize, 24, 28, 22, 16, 8);
|
| 139 | break;
|
| 140 | }
|
| 141 | return rdesc;
|
| 142 | }
|
| 143 |
|
| 144 | static const struct hid_device_id elecom_devices[] = {
|
| 145 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
|
| 146 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AC) },
|
| 147 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) },
|
| 148 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_00FB) },
|
| 149 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_018F) },
|
| 150 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3DRBK_00FC) },
|
| 151 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3DRBK_018C) },
|
| 152 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT4DRBK_00FD) },
|
| 153 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT4DRBK_018E) },
|
| 154 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1URBK) },
|
| 155 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1DRBK) },
|
| 156 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT2DRBK) },
|
| 157 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1URBK_010C) },
|
| 158 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1URBK_019B) },
|
| 159 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1DRBK_010D) },
|
| 160 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1DRBK_011C) },
|
| 161 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK) },
|
| 162 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AB) },
|
| 163 | { }
|
| 164 | };
|
| 165 | MODULE_DEVICE_TABLE(hid, elecom_devices);
|
| 166 |
|
| 167 | static struct hid_driver elecom_driver = {
|
| 168 | .name = "elecom",
|
| 169 | .id_table = elecom_devices,
|
| 170 | .report_fixup = elecom_report_fixup
|
| 171 | };
|
| 172 | module_hid_driver(elecom_driver);
|
| 173 |
|
| 174 | MODULE_DESCRIPTION("HID driver for ELECOM devices");
|
| 175 | MODULE_LICENSE("GPL");
|