hid-elecom.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * HID driver for ELECOM devices.
  3. * Copyright (c) 2010 Richard Nauber <Richard.Nauber@gmail.com>
  4. * Copyright (c) 2016 Yuxuan Shui <yshuiv7@gmail.com>
  5. * Copyright (c) 2017 Diego Elio Pettenò <flameeyes@flameeyes.eu>
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/hid.h>
  15. #include <linux/module.h>
  16. #include "hid-ids.h"
  17. static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  18. unsigned int *rsize)
  19. {
  20. switch (hdev->product) {
  21. case USB_DEVICE_ID_ELECOM_BM084:
  22. /* The BM084 Bluetooth mouse includes a non-existing horizontal
  23. * wheel in the HID descriptor. */
  24. if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) {
  25. hid_info(hdev, "Fixing up Elecom BM084 report descriptor\n");
  26. rdesc[47] = 0x00;
  27. }
  28. break;
  29. case USB_DEVICE_ID_ELECOM_DEFT_WIRED:
  30. case USB_DEVICE_ID_ELECOM_DEFT_WIRELESS:
  31. /* The DEFT trackball has eight buttons, but its descriptor only
  32. * reports five, disabling the three Fn buttons on the top of
  33. * the mouse.
  34. *
  35. * Apply the following diff to the descriptor:
  36. *
  37. * Collection (Physical), Collection (Physical),
  38. * Report ID (1), Report ID (1),
  39. * Report Count (5), -> Report Count (8),
  40. * Report Size (1), Report Size (1),
  41. * Usage Page (Button), Usage Page (Button),
  42. * Usage Minimum (01h), Usage Minimum (01h),
  43. * Usage Maximum (05h), -> Usage Maximum (08h),
  44. * Logical Minimum (0), Logical Minimum (0),
  45. * Logical Maximum (1), Logical Maximum (1),
  46. * Input (Variable), Input (Variable),
  47. * Report Count (1), -> Report Count (0),
  48. * Report Size (3), Report Size (3),
  49. * Input (Constant), Input (Constant),
  50. * Report Size (16), Report Size (16),
  51. * Report Count (2), Report Count (2),
  52. * Usage Page (Desktop), Usage Page (Desktop),
  53. * Usage (X), Usage (X),
  54. * Usage (Y), Usage (Y),
  55. * Logical Minimum (-32768), Logical Minimum (-32768),
  56. * Logical Maximum (32767), Logical Maximum (32767),
  57. * Input (Variable, Relative), Input (Variable, Relative),
  58. * End Collection, End Collection,
  59. */
  60. if (*rsize == 213 && rdesc[13] == 5 && rdesc[21] == 5) {
  61. hid_info(hdev, "Fixing up Elecom DEFT Fn buttons\n");
  62. rdesc[13] = 8; /* Button/Variable Report Count */
  63. rdesc[21] = 8; /* Button/Variable Usage Maximum */
  64. rdesc[29] = 0; /* Button/Constant Report Count */
  65. }
  66. break;
  67. }
  68. return rdesc;
  69. }
  70. static const struct hid_device_id elecom_devices[] = {
  71. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
  72. { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRED) },
  73. { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRELESS) },
  74. { }
  75. };
  76. MODULE_DEVICE_TABLE(hid, elecom_devices);
  77. static struct hid_driver elecom_driver = {
  78. .name = "elecom",
  79. .id_table = elecom_devices,
  80. .report_fixup = elecom_report_fixup
  81. };
  82. module_hid_driver(elecom_driver);
  83. MODULE_LICENSE("GPL");