summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-xiaomi.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-11-05 08:31:51 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2021-11-05 08:31:51 -0700
commit5af06603c4090617be216a9185193a7be3ca60af (patch)
tree6858833a51780dfec5076d3cdbdf4d673816e95d /drivers/hid/hid-xiaomi.c
parent5a1bcbd965341537c354e3682f939a7274ac3f5d (diff)
parent5a2506bb8cb3e618fd79966a92454edac67fb468 (diff)
downloadlinux-stable-5af06603c4090617be216a9185193a7be3ca60af.tar.gz
linux-stable-5af06603c4090617be216a9185193a7be3ca60af.tar.bz2
linux-stable-5af06603c4090617be216a9185193a7be3ca60af.zip
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Jiri Kosina: - support for Nintendo Switch Pro Controllers and Joy-Cons (Daniel J. Ogorchock) - support for new revision of the NitroKey U2F device firmware (Andrej Shadura) - LED handling improvements for Sony Playstation5 controllers (Roderick Colenbrander) - support for Apple 2021 Magic Keyboard (Alex Henrie) - other assorted code cleanups and new device ID additions * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (41 commits) HID: nintendo: fix -Werror build HID: playstation: require multicolor LED functionality HID: u2fzero: properly handle timeouts in usb_submit_urb HID: u2fzero: clarify error check and length calculations HID: u2fzero: Support NitroKey U2F revision of the device HID: wacom: Make use of the helper function devm_add_action_or_reset() HID: wacom: Shrink critical section in `wacom_add_shared_data` HID: nintendo: prevent needless queueing of the rumble worker HID: nintendo: ratelimit subcommands and rumble HID: nintendo: improve rumble performance and stability HID: nintendo: add IMU support HID: nintendo: add support for reading user calibration HID: nintendo: add support for charging grip HID: nintendo: set controller uniq to MAC HID: nintendo: reduce device removal subcommand errors HID: nintendo: patch hw version for userspace HID mappings HID: nintendo: send subcommands after receiving input report HID: nintendo: improve subcommand reliability HID: nintendo: add rumble support HID: nintendo: add home led support ...
Diffstat (limited to 'drivers/hid/hid-xiaomi.c')
-rw-r--r--drivers/hid/hid-xiaomi.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/drivers/hid/hid-xiaomi.c b/drivers/hid/hid-xiaomi.c
new file mode 100644
index 000000000000..a97a90afad33
--- /dev/null
+++ b/drivers/hid/hid-xiaomi.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * HID driver for Xiaomi Mi Dual Mode Wireless Mouse Silent Edition
+ *
+ * Copyright (c) 2021 Ilya Skriblovsky
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/hid.h>
+
+#include "hid-ids.h"
+
+/* Fixed Mi Silent Mouse report descriptor */
+/* Button's Usage Maximum changed from 3 to 5 to make side buttons work */
+#define MI_SILENT_MOUSE_ORIG_RDESC_LENGTH 87
+static __u8 mi_silent_mouse_rdesc_fixed[] = {
+ 0x05, 0x01, /* Usage Page (Desktop), */
+ 0x09, 0x02, /* Usage (Mouse), */
+ 0xA1, 0x01, /* Collection (Application), */
+ 0x85, 0x03, /* Report ID (3), */
+ 0x09, 0x01, /* Usage (Pointer), */
+ 0xA1, 0x00, /* Collection (Physical), */
+ 0x05, 0x09, /* Usage Page (Button), */
+ 0x19, 0x01, /* Usage Minimum (01h), */
+ 0x29, 0x05, /* X */ /* Usage Maximum (05h), */
+ 0x15, 0x00, /* Logical Minimum (0), */
+ 0x25, 0x01, /* Logical Maximum (1), */
+ 0x75, 0x01, /* Report Size (1), */
+ 0x95, 0x05, /* Report Count (5), */
+ 0x81, 0x02, /* Input (Variable), */
+ 0x75, 0x03, /* Report Size (3), */
+ 0x95, 0x01, /* Report Count (1), */
+ 0x81, 0x01, /* Input (Constant), */
+ 0x05, 0x01, /* Usage Page (Desktop), */
+ 0x09, 0x30, /* Usage (X), */
+ 0x09, 0x31, /* Usage (Y), */
+ 0x15, 0x81, /* Logical Minimum (-127), */
+ 0x25, 0x7F, /* Logical Maximum (127), */
+ 0x75, 0x08, /* Report Size (8), */
+ 0x95, 0x02, /* Report Count (2), */
+ 0x81, 0x06, /* Input (Variable, Relative), */
+ 0x09, 0x38, /* Usage (Wheel), */
+ 0x15, 0x81, /* Logical Minimum (-127), */
+ 0x25, 0x7F, /* Logical Maximum (127), */
+ 0x75, 0x08, /* Report Size (8), */
+ 0x95, 0x01, /* Report Count (1), */
+ 0x81, 0x06, /* Input (Variable, Relative), */
+ 0xC0, /* End Collection, */
+ 0xC0, /* End Collection, */
+ 0x06, 0x01, 0xFF, /* Usage Page (FF01h), */
+ 0x09, 0x01, /* Usage (01h), */
+ 0xA1, 0x01, /* Collection (Application), */
+ 0x85, 0x05, /* Report ID (5), */
+ 0x09, 0x05, /* Usage (05h), */
+ 0x15, 0x00, /* Logical Minimum (0), */
+ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
+ 0x75, 0x08, /* Report Size (8), */
+ 0x95, 0x04, /* Report Count (4), */
+ 0xB1, 0x02, /* Feature (Variable), */
+ 0xC0 /* End Collection */
+};
+
+static __u8 *xiaomi_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+ unsigned int *rsize)
+{
+ switch (hdev->product) {
+ case USB_DEVICE_ID_MI_SILENT_MOUSE:
+ if (*rsize == MI_SILENT_MOUSE_ORIG_RDESC_LENGTH) {
+ hid_info(hdev, "fixing up Mi Silent Mouse report descriptor\n");
+ rdesc = mi_silent_mouse_rdesc_fixed;
+ *rsize = sizeof(mi_silent_mouse_rdesc_fixed);
+ }
+ break;
+ }
+ return rdesc;
+}
+
+static const struct hid_device_id xiaomi_devices[] = {
+ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_XIAOMI, USB_DEVICE_ID_MI_SILENT_MOUSE) },
+ { }
+};
+MODULE_DEVICE_TABLE(hid, xiaomi_devices);
+
+static struct hid_driver xiaomi_driver = {
+ .name = "xiaomi",
+ .id_table = xiaomi_devices,
+ .report_fixup = xiaomi_report_fixup,
+};
+module_hid_driver(xiaomi_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ilya Skriblovsky <IlyaSkriblovsky@gmail.com>");
+MODULE_DESCRIPTION("Fixing side buttons of Xiaomi Mi Silent Mouse");