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/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18
19#include "hid-ids.h"
20
21/* Size of the original descriptor of PD1011 signature pad */
22#define PD1011_RDESC_ORIG_SIZE 408
23
24/* Fixed report descriptor of PD1011 signature pad */
25static __u8 pd1011_rdesc_fixed[] = {
26 0x05, 0x0D, /* Usage Page (Digitizer), */
27 0x09, 0x02, /* Usage (Pen), */
28 0xA1, 0x01, /* Collection (Application), */
29 0x85, 0x02, /* Report ID (2), */
30 0x09, 0x20, /* Usage (Stylus), */
31 0xA0, /* Collection (Physical), */
32 0x75, 0x10, /* Report Size (16), */
33 0x95, 0x01, /* Report Count (1), */
34 0xA4, /* Push, */
35 0x05, 0x01, /* Usage Page (Desktop), */
36 0x65, 0x13, /* Unit (Inch), */
37 0x55, 0xFD, /* Unit Exponent (-3), */
38 0x34, /* Physical Minimum (0), */
39 0x09, 0x30, /* Usage (X), */
40 0x46, 0x5D, 0x21, /* Physical Maximum (8541), */
41 0x27, 0x80, 0xA9,
42 0x00, 0x00, /* Logical Maximum (43392), */
43 0x81, 0x02, /* Input (Variable), */
44 0x09, 0x31, /* Usage (Y), */
45 0x46, 0xDA, 0x14, /* Physical Maximum (5338), */
46 0x26, 0xF0, 0x69, /* Logical Maximum (27120), */
47 0x81, 0x02, /* Input (Variable), */
48 0xB4, /* Pop, */
49 0x14, /* Logical Minimum (0), */
50 0x25, 0x01, /* Logical Maximum (1), */
51 0x75, 0x01, /* Report Size (1), */
52 0x95, 0x01, /* Report Count (1), */
53 0x81, 0x03, /* Input (Constant, Variable), */
54 0x09, 0x32, /* Usage (In Range), */
55 0x09, 0x42, /* Usage (Tip Switch), */
56 0x95, 0x02, /* Report Count (2), */
57 0x81, 0x02, /* Input (Variable), */
58 0x95, 0x05, /* Report Count (5), */
59 0x81, 0x03, /* Input (Constant, Variable), */
60 0x75, 0x10, /* Report Size (16), */
61 0x95, 0x01, /* Report Count (1), */
62 0x09, 0x30, /* Usage (Tip Pressure), */
63 0x15, 0x05, /* Logical Minimum (5), */
64 0x26, 0xFF, 0x07, /* Logical Maximum (2047), */
65 0x81, 0x02, /* Input (Variable), */
66 0x75, 0x10, /* Report Size (16), */
67 0x95, 0x01, /* Report Count (1), */
68 0x81, 0x03, /* Input (Constant, Variable), */
69 0xC0, /* End Collection, */
70 0xC0 /* End Collection */
71};
72
73static __u8 *viewsonic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
74 unsigned int *rsize)
75{
76 switch (hdev->product) {
77 case USB_DEVICE_ID_VIEWSONIC_PD1011:
78 case USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011:
79 if (*rsize == PD1011_RDESC_ORIG_SIZE) {
80 rdesc = pd1011_rdesc_fixed;
81 *rsize = sizeof(pd1011_rdesc_fixed);
82 }
83 break;
84 }
85
86 return rdesc;
87}
88
89static const struct hid_device_id viewsonic_devices[] = {
90 { HID_USB_DEVICE(USB_VENDOR_ID_VIEWSONIC,
91 USB_DEVICE_ID_VIEWSONIC_PD1011) },
92 { HID_USB_DEVICE(USB_VENDOR_ID_SIGNOTEC,
93 USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011) },
94 { }
95};
96MODULE_DEVICE_TABLE(hid, viewsonic_devices);
97
98static struct hid_driver viewsonic_driver = {
99 .name = "viewsonic",
100 .id_table = viewsonic_devices,
101 .report_fixup = viewsonic_report_fixup,
102};
103module_hid_driver(viewsonic_driver);
104
105MODULE_LICENSE("GPL");
106