hid-viewsonic.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * HID driver for ViewSonic devices not fully compliant with HID standard
  4. *
  5. * Copyright (c) 2017 Nikolai Kondrashov
  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. /* Size of the original descriptor of PD1011 signature pad */
  18. #define PD1011_RDESC_ORIG_SIZE 408
  19. /* Fixed report descriptor of PD1011 signature pad */
  20. static __u8 pd1011_rdesc_fixed[] = {
  21. 0x05, 0x0D, /* Usage Page (Digitizer), */
  22. 0x09, 0x01, /* Usage (Digitizer), */
  23. 0xA1, 0x01, /* Collection (Application), */
  24. 0x85, 0x02, /* Report ID (2), */
  25. 0x09, 0x20, /* Usage (Stylus), */
  26. 0xA0, /* Collection (Physical), */
  27. 0x75, 0x10, /* Report Size (16), */
  28. 0x95, 0x01, /* Report Count (1), */
  29. 0xA4, /* Push, */
  30. 0x05, 0x01, /* Usage Page (Desktop), */
  31. 0x65, 0x13, /* Unit (Inch), */
  32. 0x55, 0xFD, /* Unit Exponent (-3), */
  33. 0x34, /* Physical Minimum (0), */
  34. 0x09, 0x30, /* Usage (X), */
  35. 0x46, 0x5D, 0x21, /* Physical Maximum (8541), */
  36. 0x27, 0x80, 0xA9,
  37. 0x00, 0x00, /* Logical Maximum (43392), */
  38. 0x81, 0x02, /* Input (Variable), */
  39. 0x09, 0x31, /* Usage (Y), */
  40. 0x46, 0xDA, 0x14, /* Physical Maximum (5338), */
  41. 0x26, 0xF0, 0x69, /* Logical Maximum (27120), */
  42. 0x81, 0x02, /* Input (Variable), */
  43. 0xB4, /* Pop, */
  44. 0x14, /* Logical Minimum (0), */
  45. 0x25, 0x01, /* Logical Maximum (1), */
  46. 0x75, 0x01, /* Report Size (1), */
  47. 0x95, 0x01, /* Report Count (1), */
  48. 0x81, 0x03, /* Input (Constant, Variable), */
  49. 0x09, 0x32, /* Usage (In Range), */
  50. 0x09, 0x42, /* Usage (Tip Switch), */
  51. 0x95, 0x02, /* Report Count (2), */
  52. 0x81, 0x02, /* Input (Variable), */
  53. 0x95, 0x05, /* Report Count (5), */
  54. 0x81, 0x03, /* Input (Constant, Variable), */
  55. 0x75, 0x10, /* Report Size (16), */
  56. 0x95, 0x01, /* Report Count (1), */
  57. 0x09, 0x30, /* Usage (Tip Pressure), */
  58. 0x15, 0x05, /* Logical Minimum (5), */
  59. 0x26, 0xFF, 0x07, /* Logical Maximum (2047), */
  60. 0x81, 0x02, /* Input (Variable), */
  61. 0x75, 0x10, /* Report Size (16), */
  62. 0x95, 0x01, /* Report Count (1), */
  63. 0x81, 0x03, /* Input (Constant, Variable), */
  64. 0xC0, /* End Collection, */
  65. 0xC0 /* End Collection */
  66. };
  67. static __u8 *viewsonic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  68. unsigned int *rsize)
  69. {
  70. switch (hdev->product) {
  71. case USB_DEVICE_ID_VIEWSONIC_PD1011:
  72. case USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011:
  73. if (*rsize == PD1011_RDESC_ORIG_SIZE) {
  74. rdesc = pd1011_rdesc_fixed;
  75. *rsize = sizeof(pd1011_rdesc_fixed);
  76. }
  77. break;
  78. }
  79. return rdesc;
  80. }
  81. static const struct hid_device_id viewsonic_devices[] = {
  82. { HID_USB_DEVICE(USB_VENDOR_ID_VIEWSONIC,
  83. USB_DEVICE_ID_VIEWSONIC_PD1011) },
  84. { HID_USB_DEVICE(USB_VENDOR_ID_SIGNOTEC,
  85. USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011) },
  86. { }
  87. };
  88. MODULE_DEVICE_TABLE(hid, viewsonic_devices);
  89. static struct hid_driver viewsonic_driver = {
  90. .name = "viewsonic",
  91. .id_table = viewsonic_devices,
  92. .report_fixup = viewsonic_report_fixup,
  93. };
  94. module_hid_driver(viewsonic_driver);
  95. MODULE_LICENSE("GPL");