Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 2 | /* |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 3 | * HID driver for ELECOM devices: |
| 4 | * - BM084 Bluetooth Mouse |
Tomasz Kramkowski | fbb77e8 | 2018-03-01 17:22:24 +0000 | [diff] [blame] | 5 | * - EX-G Trackballs (M-XT3DRBK, M-XT3URBK, M-XT4DRBK) |
Tomasz Kramkowski | 79837ed | 2018-03-01 17:22:23 +0000 | [diff] [blame] | 6 | * - DEFT Trackballs (M-DT1DRBK, M-DT1URBK, M-DT2DRBK, M-DT2URBK) |
| 7 | * - HUGE Trackballs (M-HT1DRBK, M-HT1URBK) |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 8 | * |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 9 | * Copyright (c) 2010 Richard Nauber <Richard.Nauber@gmail.com> |
Diego Elio Pettenò | 0bb7a37 | 2017-04-26 17:37:04 +0100 | [diff] [blame] | 10 | * Copyright (c) 2016 Yuxuan Shui <yshuiv7@gmail.com> |
| 11 | * Copyright (c) 2017 Diego Elio Pettenò <flameeyes@flameeyes.eu> |
Alex Manoussakis | a0933a4 | 2017-10-05 13:41:20 -0400 | [diff] [blame] | 12 | * Copyright (c) 2017 Alex Manoussakis <amanou@gnu.org> |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 13 | * Copyright (c) 2017 Tomasz Kramkowski <tk@the-tk.com> |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/hid.h> |
| 21 | #include <linux/module.h> |
| 22 | |
| 23 | #include "hid-ids.h" |
| 24 | |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 25 | /* |
| 26 | * Certain ELECOM mice misreport their button count meaning that they only work |
| 27 | * correctly with the ELECOM mouse assistant software which is unavailable for |
| 28 | * Linux. A four extra INPUT reports and a FEATURE report are described by the |
| 29 | * report descriptor but it does not appear that these enable software to |
| 30 | * control what the extra buttons map to. The only simple and straightforward |
| 31 | * solution seems to involve fixing up the report descriptor. |
| 32 | * |
| 33 | * Report descriptor format: |
| 34 | * Positions 13, 15, 21 and 31 store the button bit count, button usage minimum, |
| 35 | * button usage maximum and padding bit count respectively. |
| 36 | */ |
| 37 | #define MOUSE_BUTTONS_MAX 8 |
| 38 | static void mouse_button_fixup(struct hid_device *hdev, |
| 39 | __u8 *rdesc, unsigned int rsize, |
| 40 | int nbuttons) |
| 41 | { |
| 42 | if (rsize < 32 || rdesc[12] != 0x95 || |
| 43 | rdesc[14] != 0x75 || rdesc[15] != 0x01 || |
| 44 | rdesc[20] != 0x29 || rdesc[30] != 0x75) |
| 45 | return; |
| 46 | hid_info(hdev, "Fixing up Elecom mouse button count\n"); |
| 47 | nbuttons = clamp(nbuttons, 0, MOUSE_BUTTONS_MAX); |
| 48 | rdesc[13] = nbuttons; |
| 49 | rdesc[21] = nbuttons; |
| 50 | rdesc[31] = MOUSE_BUTTONS_MAX - nbuttons; |
| 51 | } |
| 52 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 53 | static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 54 | unsigned int *rsize) |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 55 | { |
Diego Elio Pettenò | 0bb7a37 | 2017-04-26 17:37:04 +0100 | [diff] [blame] | 56 | switch (hdev->product) { |
| 57 | case USB_DEVICE_ID_ELECOM_BM084: |
| 58 | /* The BM084 Bluetooth mouse includes a non-existing horizontal |
| 59 | * wheel in the HID descriptor. */ |
| 60 | if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) { |
| 61 | hid_info(hdev, "Fixing up Elecom BM084 report descriptor\n"); |
| 62 | rdesc[47] = 0x00; |
| 63 | } |
| 64 | break; |
Tomasz Kramkowski | 79837ed | 2018-03-01 17:22:23 +0000 | [diff] [blame] | 65 | case USB_DEVICE_ID_ELECOM_M_XT3URBK: |
| 66 | case USB_DEVICE_ID_ELECOM_M_XT3DRBK: |
Tomasz Kramkowski | fbb77e8 | 2018-03-01 17:22:24 +0000 | [diff] [blame] | 67 | case USB_DEVICE_ID_ELECOM_M_XT4DRBK: |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 68 | mouse_button_fixup(hdev, rdesc, *rsize, 6); |
| 69 | break; |
Tomasz Kramkowski | 79837ed | 2018-03-01 17:22:23 +0000 | [diff] [blame] | 70 | case USB_DEVICE_ID_ELECOM_M_DT1URBK: |
| 71 | case USB_DEVICE_ID_ELECOM_M_DT1DRBK: |
| 72 | case USB_DEVICE_ID_ELECOM_M_HT1URBK: |
| 73 | case USB_DEVICE_ID_ELECOM_M_HT1DRBK: |
Tomasz Kramkowski | ac58eec | 2017-12-19 20:44:36 +0000 | [diff] [blame] | 74 | mouse_button_fixup(hdev, rdesc, *rsize, 8); |
Diego Elio Pettenò | 0bb7a37 | 2017-04-26 17:37:04 +0100 | [diff] [blame] | 75 | break; |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 76 | } |
Jiri Slaby | 636a89d | 2015-10-11 16:18:22 +0200 | [diff] [blame] | 77 | return rdesc; |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static const struct hid_device_id elecom_devices[] = { |
Diego Elio Pettenò | 0bb7a37 | 2017-04-26 17:37:04 +0100 | [diff] [blame] | 81 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, |
Tomasz Kramkowski | 79837ed | 2018-03-01 17:22:23 +0000 | [diff] [blame] | 82 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK) }, |
| 83 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3DRBK) }, |
Tomasz Kramkowski | fbb77e8 | 2018-03-01 17:22:24 +0000 | [diff] [blame] | 84 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT4DRBK) }, |
Tomasz Kramkowski | 79837ed | 2018-03-01 17:22:23 +0000 | [diff] [blame] | 85 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1URBK) }, |
| 86 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1DRBK) }, |
| 87 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1URBK) }, |
| 88 | { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1DRBK) }, |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 89 | { } |
| 90 | }; |
| 91 | MODULE_DEVICE_TABLE(hid, elecom_devices); |
| 92 | |
| 93 | static struct hid_driver elecom_driver = { |
| 94 | .name = "elecom", |
| 95 | .id_table = elecom_devices, |
| 96 | .report_fixup = elecom_report_fixup |
| 97 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 98 | module_hid_driver(elecom_driver); |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 99 | |
Richard Nauber | 64b386e | 2010-06-28 18:54:25 +0200 | [diff] [blame] | 100 | MODULE_LICENSE("GPL"); |