diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hid/Kconfig | 8 | ||||
-rw-r--r-- | drivers/hid/Makefile | 1 | ||||
-rw-r--r-- | drivers/hid/hid-huion.c | 290 | ||||
-rw-r--r-- | drivers/hid/hid-uclogic.c | 229 |
4 files changed, 229 insertions, 299 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 152b006833cd..8a55fd7f1fe3 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -286,12 +286,6 @@ config HID_GT683R | |||
286 | Currently the following devices are know to be supported: | 286 | Currently the following devices are know to be supported: |
287 | - MSI GT683R | 287 | - MSI GT683R |
288 | 288 | ||
289 | config HID_HUION | ||
290 | tristate "Huion tablets" | ||
291 | depends on USB_HID | ||
292 | ---help--- | ||
293 | Support for Huion 580 tablet. | ||
294 | |||
295 | config HID_KEYTOUCH | 289 | config HID_KEYTOUCH |
296 | tristate "Keytouch HID devices" | 290 | tristate "Keytouch HID devices" |
297 | depends on HID | 291 | depends on HID |
@@ -314,7 +308,7 @@ config HID_UCLOGIC | |||
314 | tristate "UC-Logic" | 308 | tristate "UC-Logic" |
315 | depends on HID | 309 | depends on HID |
316 | ---help--- | 310 | ---help--- |
317 | Support for UC-Logic tablets. | 311 | Support for UC-Logic and Huion tablets. |
318 | 312 | ||
319 | config HID_WALTOP | 313 | config HID_WALTOP |
320 | tristate "Waltop" | 314 | tristate "Waltop" |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 6f19958dfc38..9c399fe394fa 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -41,7 +41,6 @@ obj-$(CONFIG_HID_GYRATION) += hid-gyration.o | |||
41 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o | 41 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o |
42 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o | 42 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o |
43 | obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o | 43 | obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o |
44 | obj-$(CONFIG_HID_HUION) += hid-huion.o | ||
45 | obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o | 44 | obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o |
46 | obj-$(CONFIG_HID_ICADE) += hid-icade.o | 45 | obj-$(CONFIG_HID_ICADE) += hid-icade.o |
47 | obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o | 46 | obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o |
diff --git a/drivers/hid/hid-huion.c b/drivers/hid/hid-huion.c deleted file mode 100644 index 61b68ca27790..000000000000 --- a/drivers/hid/hid-huion.c +++ /dev/null | |||
@@ -1,290 +0,0 @@ | |||
1 | /* | ||
2 | * HID driver for Huion devices not fully compliant with HID standard | ||
3 | * | ||
4 | * Copyright (c) 2013 Martin Rusko | ||
5 | * Copyright (c) 2014 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 | #include <linux/usb.h> | ||
19 | #include <asm/unaligned.h> | ||
20 | #include "usbhid/usbhid.h" | ||
21 | |||
22 | #include "hid-ids.h" | ||
23 | |||
24 | /* Report descriptor template placeholder head */ | ||
25 | #define HUION_PH_HEAD 0xFE, 0xED, 0x1D | ||
26 | |||
27 | /* Report descriptor template placeholder IDs */ | ||
28 | enum huion_ph_id { | ||
29 | HUION_PH_ID_X_LM, | ||
30 | HUION_PH_ID_X_PM, | ||
31 | HUION_PH_ID_Y_LM, | ||
32 | HUION_PH_ID_Y_PM, | ||
33 | HUION_PH_ID_PRESSURE_LM, | ||
34 | HUION_PH_ID_NUM | ||
35 | }; | ||
36 | |||
37 | /* Report descriptor template placeholder */ | ||
38 | #define HUION_PH(_ID) HUION_PH_HEAD, HUION_PH_ID_##_ID | ||
39 | |||
40 | /* Fixed report descriptor template */ | ||
41 | static const __u8 huion_tablet_rdesc_template[] = { | ||
42 | 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
43 | 0x09, 0x02, /* Usage (Pen), */ | ||
44 | 0xA1, 0x01, /* Collection (Application), */ | ||
45 | 0x85, 0x07, /* Report ID (7), */ | ||
46 | 0x09, 0x20, /* Usage (Stylus), */ | ||
47 | 0xA0, /* Collection (Physical), */ | ||
48 | 0x14, /* Logical Minimum (0), */ | ||
49 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
50 | 0x75, 0x01, /* Report Size (1), */ | ||
51 | 0x09, 0x42, /* Usage (Tip Switch), */ | ||
52 | 0x09, 0x44, /* Usage (Barrel Switch), */ | ||
53 | 0x09, 0x46, /* Usage (Tablet Pick), */ | ||
54 | 0x95, 0x03, /* Report Count (3), */ | ||
55 | 0x81, 0x02, /* Input (Variable), */ | ||
56 | 0x95, 0x03, /* Report Count (3), */ | ||
57 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
58 | 0x09, 0x32, /* Usage (In Range), */ | ||
59 | 0x95, 0x01, /* Report Count (1), */ | ||
60 | 0x81, 0x02, /* Input (Variable), */ | ||
61 | 0x95, 0x01, /* Report Count (1), */ | ||
62 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
63 | 0x75, 0x10, /* Report Size (16), */ | ||
64 | 0x95, 0x01, /* Report Count (1), */ | ||
65 | 0xA4, /* Push, */ | ||
66 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
67 | 0x65, 0x13, /* Unit (Inch), */ | ||
68 | 0x55, 0xFD, /* Unit Exponent (-3), */ | ||
69 | 0x34, /* Physical Minimum (0), */ | ||
70 | 0x09, 0x30, /* Usage (X), */ | ||
71 | 0x27, HUION_PH(X_LM), /* Logical Maximum (PLACEHOLDER), */ | ||
72 | 0x47, HUION_PH(X_PM), /* Physical Maximum (PLACEHOLDER), */ | ||
73 | 0x81, 0x02, /* Input (Variable), */ | ||
74 | 0x09, 0x31, /* Usage (Y), */ | ||
75 | 0x27, HUION_PH(Y_LM), /* Logical Maximum (PLACEHOLDER), */ | ||
76 | 0x47, HUION_PH(Y_PM), /* Physical Maximum (PLACEHOLDER), */ | ||
77 | 0x81, 0x02, /* Input (Variable), */ | ||
78 | 0xB4, /* Pop, */ | ||
79 | 0x09, 0x30, /* Usage (Tip Pressure), */ | ||
80 | 0x27, | ||
81 | HUION_PH(PRESSURE_LM), /* Logical Maximum (PLACEHOLDER), */ | ||
82 | 0x81, 0x02, /* Input (Variable), */ | ||
83 | 0xC0, /* End Collection, */ | ||
84 | 0xC0 /* End Collection */ | ||
85 | }; | ||
86 | |||
87 | /* Parameter indices */ | ||
88 | enum huion_prm { | ||
89 | HUION_PRM_X_LM = 1, | ||
90 | HUION_PRM_Y_LM = 2, | ||
91 | HUION_PRM_PRESSURE_LM = 4, | ||
92 | HUION_PRM_RESOLUTION = 5, | ||
93 | HUION_PRM_NUM | ||
94 | }; | ||
95 | |||
96 | /* Driver data */ | ||
97 | struct huion_drvdata { | ||
98 | __u8 *rdesc; | ||
99 | unsigned int rsize; | ||
100 | }; | ||
101 | |||
102 | static __u8 *huion_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
103 | unsigned int *rsize) | ||
104 | { | ||
105 | struct huion_drvdata *drvdata = hid_get_drvdata(hdev); | ||
106 | switch (hdev->product) { | ||
107 | case USB_DEVICE_ID_HUION_TABLET: | ||
108 | if (drvdata->rdesc != NULL) { | ||
109 | rdesc = drvdata->rdesc; | ||
110 | *rsize = drvdata->rsize; | ||
111 | } | ||
112 | break; | ||
113 | } | ||
114 | return rdesc; | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Enable fully-functional tablet mode and determine device parameters. | ||
119 | * | ||
120 | * @hdev: HID device | ||
121 | */ | ||
122 | static int huion_tablet_enable(struct hid_device *hdev) | ||
123 | { | ||
124 | int rc; | ||
125 | struct usb_device *usb_dev = hid_to_usb_dev(hdev); | ||
126 | struct huion_drvdata *drvdata = hid_get_drvdata(hdev); | ||
127 | __le16 *buf = NULL; | ||
128 | size_t len; | ||
129 | s32 params[HUION_PH_ID_NUM]; | ||
130 | s32 resolution; | ||
131 | __u8 *p; | ||
132 | s32 v; | ||
133 | |||
134 | /* | ||
135 | * Read string descriptor containing tablet parameters. The specific | ||
136 | * string descriptor and data were discovered by sniffing the Windows | ||
137 | * driver traffic. | ||
138 | * NOTE: This enables fully-functional tablet mode. | ||
139 | */ | ||
140 | len = HUION_PRM_NUM * sizeof(*buf); | ||
141 | buf = kmalloc(len, GFP_KERNEL); | ||
142 | if (buf == NULL) { | ||
143 | hid_err(hdev, "failed to allocate parameter buffer\n"); | ||
144 | rc = -ENOMEM; | ||
145 | goto cleanup; | ||
146 | } | ||
147 | rc = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | ||
148 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, | ||
149 | (USB_DT_STRING << 8) + 0x64, | ||
150 | 0x0409, buf, len, | ||
151 | USB_CTRL_GET_TIMEOUT); | ||
152 | if (rc == -EPIPE) { | ||
153 | hid_err(hdev, "device parameters not found\n"); | ||
154 | rc = -ENODEV; | ||
155 | goto cleanup; | ||
156 | } else if (rc < 0) { | ||
157 | hid_err(hdev, "failed to get device parameters: %d\n", rc); | ||
158 | rc = -ENODEV; | ||
159 | goto cleanup; | ||
160 | } else if (rc != len) { | ||
161 | hid_err(hdev, "invalid device parameters\n"); | ||
162 | rc = -ENODEV; | ||
163 | goto cleanup; | ||
164 | } | ||
165 | |||
166 | /* Extract device parameters */ | ||
167 | params[HUION_PH_ID_X_LM] = le16_to_cpu(buf[HUION_PRM_X_LM]); | ||
168 | params[HUION_PH_ID_Y_LM] = le16_to_cpu(buf[HUION_PRM_Y_LM]); | ||
169 | params[HUION_PH_ID_PRESSURE_LM] = | ||
170 | le16_to_cpu(buf[HUION_PRM_PRESSURE_LM]); | ||
171 | resolution = le16_to_cpu(buf[HUION_PRM_RESOLUTION]); | ||
172 | if (resolution == 0) { | ||
173 | params[HUION_PH_ID_X_PM] = 0; | ||
174 | params[HUION_PH_ID_Y_PM] = 0; | ||
175 | } else { | ||
176 | params[HUION_PH_ID_X_PM] = params[HUION_PH_ID_X_LM] * | ||
177 | 1000 / resolution; | ||
178 | params[HUION_PH_ID_Y_PM] = params[HUION_PH_ID_Y_LM] * | ||
179 | 1000 / resolution; | ||
180 | } | ||
181 | |||
182 | /* Allocate fixed report descriptor */ | ||
183 | drvdata->rdesc = devm_kmalloc(&hdev->dev, | ||
184 | sizeof(huion_tablet_rdesc_template), | ||
185 | GFP_KERNEL); | ||
186 | if (drvdata->rdesc == NULL) { | ||
187 | hid_err(hdev, "failed to allocate fixed rdesc\n"); | ||
188 | rc = -ENOMEM; | ||
189 | goto cleanup; | ||
190 | } | ||
191 | drvdata->rsize = sizeof(huion_tablet_rdesc_template); | ||
192 | |||
193 | /* Format fixed report descriptor */ | ||
194 | memcpy(drvdata->rdesc, huion_tablet_rdesc_template, | ||
195 | drvdata->rsize); | ||
196 | for (p = drvdata->rdesc; | ||
197 | p <= drvdata->rdesc + drvdata->rsize - 4;) { | ||
198 | if (p[0] == 0xFE && p[1] == 0xED && p[2] == 0x1D && | ||
199 | p[3] < sizeof(params)) { | ||
200 | v = params[p[3]]; | ||
201 | put_unaligned(cpu_to_le32(v), (s32 *)p); | ||
202 | p += 4; | ||
203 | } else { | ||
204 | p++; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | rc = 0; | ||
209 | |||
210 | cleanup: | ||
211 | kfree(buf); | ||
212 | return rc; | ||
213 | } | ||
214 | |||
215 | static int huion_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
216 | { | ||
217 | int rc; | ||
218 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
219 | struct huion_drvdata *drvdata; | ||
220 | |||
221 | /* Allocate and assign driver data */ | ||
222 | drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); | ||
223 | if (drvdata == NULL) { | ||
224 | hid_err(hdev, "failed to allocate driver data\n"); | ||
225 | return -ENOMEM; | ||
226 | } | ||
227 | hid_set_drvdata(hdev, drvdata); | ||
228 | |||
229 | switch (id->product) { | ||
230 | case USB_DEVICE_ID_HUION_TABLET: | ||
231 | /* If this is the pen interface */ | ||
232 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { | ||
233 | rc = huion_tablet_enable(hdev); | ||
234 | if (rc) { | ||
235 | hid_err(hdev, "tablet enabling failed\n"); | ||
236 | return rc; | ||
237 | } | ||
238 | } | ||
239 | break; | ||
240 | } | ||
241 | |||
242 | rc = hid_parse(hdev); | ||
243 | if (rc) { | ||
244 | hid_err(hdev, "parse failed\n"); | ||
245 | return rc; | ||
246 | } | ||
247 | |||
248 | rc = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
249 | if (rc) { | ||
250 | hid_err(hdev, "hw start failed\n"); | ||
251 | return rc; | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int huion_raw_event(struct hid_device *hdev, struct hid_report *report, | ||
258 | u8 *data, int size) | ||
259 | { | ||
260 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
261 | |||
262 | /* If this is a pen input report */ | ||
263 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0 && | ||
264 | report->type == HID_INPUT_REPORT && | ||
265 | report->id == 0x07 && size >= 2) | ||
266 | /* Invert the in-range bit */ | ||
267 | data[1] ^= 0x40; | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static const struct hid_device_id huion_devices[] = { | ||
273 | { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) }, | ||
274 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) }, | ||
275 | { } | ||
276 | }; | ||
277 | MODULE_DEVICE_TABLE(hid, huion_devices); | ||
278 | |||
279 | static struct hid_driver huion_driver = { | ||
280 | .name = "huion", | ||
281 | .id_table = huion_devices, | ||
282 | .probe = huion_probe, | ||
283 | .report_fixup = huion_report_fixup, | ||
284 | .raw_event = huion_raw_event, | ||
285 | }; | ||
286 | module_hid_driver(huion_driver); | ||
287 | |||
288 | MODULE_AUTHOR("Martin Rusko"); | ||
289 | MODULE_DESCRIPTION("Huion HID driver"); | ||
290 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hid/hid-uclogic.c b/drivers/hid/hid-uclogic.c index 22dccce6a85c..397f1df05d8b 100644 --- a/drivers/hid/hid-uclogic.c +++ b/drivers/hid/hid-uclogic.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * HID driver for UC-Logic devices not fully compliant with HID standard | 2 | * HID driver for UC-Logic devices not fully compliant with HID standard |
3 | * | 3 | * |
4 | * Copyright (c) 2010 Nikolai Kondrashov | 4 | * Copyright (c) 2010-2014 Nikolai Kondrashov |
5 | * Copyright (c) 2013 Martin Rusko | ||
5 | */ | 6 | */ |
6 | 7 | ||
7 | /* | 8 | /* |
@@ -15,6 +16,8 @@ | |||
15 | #include <linux/hid.h> | 16 | #include <linux/hid.h> |
16 | #include <linux/module.h> | 17 | #include <linux/module.h> |
17 | #include <linux/usb.h> | 18 | #include <linux/usb.h> |
19 | #include <asm/unaligned.h> | ||
20 | #include "usbhid/usbhid.h" | ||
18 | 21 | ||
19 | #include "hid-ids.h" | 22 | #include "hid-ids.h" |
20 | 23 | ||
@@ -546,11 +549,90 @@ static __u8 twha60_rdesc_fixed1[] = { | |||
546 | 0xC0 /* End Collection */ | 549 | 0xC0 /* End Collection */ |
547 | }; | 550 | }; |
548 | 551 | ||
552 | /* Report descriptor template placeholder head */ | ||
553 | #define UCLOGIC_PH_HEAD 0xFE, 0xED, 0x1D | ||
554 | |||
555 | /* Report descriptor template placeholder IDs */ | ||
556 | enum uclogic_ph_id { | ||
557 | UCLOGIC_PH_ID_X_LM, | ||
558 | UCLOGIC_PH_ID_X_PM, | ||
559 | UCLOGIC_PH_ID_Y_LM, | ||
560 | UCLOGIC_PH_ID_Y_PM, | ||
561 | UCLOGIC_PH_ID_PRESSURE_LM, | ||
562 | UCLOGIC_PH_ID_NUM | ||
563 | }; | ||
564 | |||
565 | /* Report descriptor template placeholder */ | ||
566 | #define UCLOGIC_PH(_ID) UCLOGIC_PH_HEAD, UCLOGIC_PH_ID_##_ID | ||
567 | |||
568 | /* Fixed report descriptor template */ | ||
569 | static const __u8 uclogic_tablet_rdesc_template[] = { | ||
570 | 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
571 | 0x09, 0x02, /* Usage (Pen), */ | ||
572 | 0xA1, 0x01, /* Collection (Application), */ | ||
573 | 0x85, 0x07, /* Report ID (7), */ | ||
574 | 0x09, 0x20, /* Usage (Stylus), */ | ||
575 | 0xA0, /* Collection (Physical), */ | ||
576 | 0x14, /* Logical Minimum (0), */ | ||
577 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
578 | 0x75, 0x01, /* Report Size (1), */ | ||
579 | 0x09, 0x42, /* Usage (Tip Switch), */ | ||
580 | 0x09, 0x44, /* Usage (Barrel Switch), */ | ||
581 | 0x09, 0x46, /* Usage (Tablet Pick), */ | ||
582 | 0x95, 0x03, /* Report Count (3), */ | ||
583 | 0x81, 0x02, /* Input (Variable), */ | ||
584 | 0x95, 0x03, /* Report Count (3), */ | ||
585 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
586 | 0x09, 0x32, /* Usage (In Range), */ | ||
587 | 0x95, 0x01, /* Report Count (1), */ | ||
588 | 0x81, 0x02, /* Input (Variable), */ | ||
589 | 0x95, 0x01, /* Report Count (1), */ | ||
590 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
591 | 0x75, 0x10, /* Report Size (16), */ | ||
592 | 0x95, 0x01, /* Report Count (1), */ | ||
593 | 0xA4, /* Push, */ | ||
594 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
595 | 0x65, 0x13, /* Unit (Inch), */ | ||
596 | 0x55, 0xFD, /* Unit Exponent (-3), */ | ||
597 | 0x34, /* Physical Minimum (0), */ | ||
598 | 0x09, 0x30, /* Usage (X), */ | ||
599 | 0x27, UCLOGIC_PH(X_LM), /* Logical Maximum (PLACEHOLDER), */ | ||
600 | 0x47, UCLOGIC_PH(X_PM), /* Physical Maximum (PLACEHOLDER), */ | ||
601 | 0x81, 0x02, /* Input (Variable), */ | ||
602 | 0x09, 0x31, /* Usage (Y), */ | ||
603 | 0x27, UCLOGIC_PH(Y_LM), /* Logical Maximum (PLACEHOLDER), */ | ||
604 | 0x47, UCLOGIC_PH(Y_PM), /* Physical Maximum (PLACEHOLDER), */ | ||
605 | 0x81, 0x02, /* Input (Variable), */ | ||
606 | 0xB4, /* Pop, */ | ||
607 | 0x09, 0x30, /* Usage (Tip Pressure), */ | ||
608 | 0x27, | ||
609 | UCLOGIC_PH(PRESSURE_LM),/* Logical Maximum (PLACEHOLDER), */ | ||
610 | 0x81, 0x02, /* Input (Variable), */ | ||
611 | 0xC0, /* End Collection, */ | ||
612 | 0xC0 /* End Collection */ | ||
613 | }; | ||
614 | |||
615 | /* Parameter indices */ | ||
616 | enum uclogic_prm { | ||
617 | UCLOGIC_PRM_X_LM = 1, | ||
618 | UCLOGIC_PRM_Y_LM = 2, | ||
619 | UCLOGIC_PRM_PRESSURE_LM = 4, | ||
620 | UCLOGIC_PRM_RESOLUTION = 5, | ||
621 | UCLOGIC_PRM_NUM | ||
622 | }; | ||
623 | |||
624 | /* Driver data */ | ||
625 | struct uclogic_drvdata { | ||
626 | __u8 *rdesc; | ||
627 | unsigned int rsize; | ||
628 | }; | ||
629 | |||
549 | static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, | 630 | static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
550 | unsigned int *rsize) | 631 | unsigned int *rsize) |
551 | { | 632 | { |
552 | struct usb_interface *iface = to_usb_interface(hdev->dev.parent); | 633 | struct usb_interface *iface = to_usb_interface(hdev->dev.parent); |
553 | __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber; | 634 | __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber; |
635 | struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev); | ||
554 | 636 | ||
555 | switch (hdev->product) { | 637 | switch (hdev->product) { |
556 | case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209: | 638 | case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209: |
@@ -621,15 +703,120 @@ static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
621 | break; | 703 | break; |
622 | } | 704 | } |
623 | break; | 705 | break; |
706 | default: | ||
707 | if (drvdata->rdesc != NULL) { | ||
708 | rdesc = drvdata->rdesc; | ||
709 | *rsize = drvdata->rsize; | ||
710 | } | ||
624 | } | 711 | } |
625 | 712 | ||
626 | return rdesc; | 713 | return rdesc; |
627 | } | 714 | } |
628 | 715 | ||
716 | /** | ||
717 | * Enable fully-functional tablet mode and determine device parameters. | ||
718 | * | ||
719 | * @hdev: HID device | ||
720 | */ | ||
721 | static int uclogic_tablet_enable(struct hid_device *hdev) | ||
722 | { | ||
723 | int rc; | ||
724 | struct usb_device *usb_dev = hid_to_usb_dev(hdev); | ||
725 | struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev); | ||
726 | __le16 *buf = NULL; | ||
727 | size_t len; | ||
728 | s32 params[UCLOGIC_PH_ID_NUM]; | ||
729 | s32 resolution; | ||
730 | __u8 *p; | ||
731 | s32 v; | ||
732 | |||
733 | /* | ||
734 | * Read string descriptor containing tablet parameters. The specific | ||
735 | * string descriptor and data were discovered by sniffing the Windows | ||
736 | * driver traffic. | ||
737 | * NOTE: This enables fully-functional tablet mode. | ||
738 | */ | ||
739 | len = UCLOGIC_PRM_NUM * sizeof(*buf); | ||
740 | buf = kmalloc(len, GFP_KERNEL); | ||
741 | if (buf == NULL) { | ||
742 | hid_err(hdev, "failed to allocate parameter buffer\n"); | ||
743 | rc = -ENOMEM; | ||
744 | goto cleanup; | ||
745 | } | ||
746 | rc = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | ||
747 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, | ||
748 | (USB_DT_STRING << 8) + 0x64, | ||
749 | 0x0409, buf, len, | ||
750 | USB_CTRL_GET_TIMEOUT); | ||
751 | if (rc == -EPIPE) { | ||
752 | hid_err(hdev, "device parameters not found\n"); | ||
753 | rc = -ENODEV; | ||
754 | goto cleanup; | ||
755 | } else if (rc < 0) { | ||
756 | hid_err(hdev, "failed to get device parameters: %d\n", rc); | ||
757 | rc = -ENODEV; | ||
758 | goto cleanup; | ||
759 | } else if (rc != len) { | ||
760 | hid_err(hdev, "invalid device parameters\n"); | ||
761 | rc = -ENODEV; | ||
762 | goto cleanup; | ||
763 | } | ||
764 | |||
765 | /* Extract device parameters */ | ||
766 | params[UCLOGIC_PH_ID_X_LM] = le16_to_cpu(buf[UCLOGIC_PRM_X_LM]); | ||
767 | params[UCLOGIC_PH_ID_Y_LM] = le16_to_cpu(buf[UCLOGIC_PRM_Y_LM]); | ||
768 | params[UCLOGIC_PH_ID_PRESSURE_LM] = | ||
769 | le16_to_cpu(buf[UCLOGIC_PRM_PRESSURE_LM]); | ||
770 | resolution = le16_to_cpu(buf[UCLOGIC_PRM_RESOLUTION]); | ||
771 | if (resolution == 0) { | ||
772 | params[UCLOGIC_PH_ID_X_PM] = 0; | ||
773 | params[UCLOGIC_PH_ID_Y_PM] = 0; | ||
774 | } else { | ||
775 | params[UCLOGIC_PH_ID_X_PM] = params[UCLOGIC_PH_ID_X_LM] * | ||
776 | 1000 / resolution; | ||
777 | params[UCLOGIC_PH_ID_Y_PM] = params[UCLOGIC_PH_ID_Y_LM] * | ||
778 | 1000 / resolution; | ||
779 | } | ||
780 | |||
781 | /* Allocate fixed report descriptor */ | ||
782 | drvdata->rdesc = devm_kzalloc(&hdev->dev, | ||
783 | sizeof(uclogic_tablet_rdesc_template), | ||
784 | GFP_KERNEL); | ||
785 | if (drvdata->rdesc == NULL) { | ||
786 | hid_err(hdev, "failed to allocate fixed rdesc\n"); | ||
787 | rc = -ENOMEM; | ||
788 | goto cleanup; | ||
789 | } | ||
790 | drvdata->rsize = sizeof(uclogic_tablet_rdesc_template); | ||
791 | |||
792 | /* Format fixed report descriptor */ | ||
793 | memcpy(drvdata->rdesc, uclogic_tablet_rdesc_template, | ||
794 | drvdata->rsize); | ||
795 | for (p = drvdata->rdesc; | ||
796 | p <= drvdata->rdesc + drvdata->rsize - 4;) { | ||
797 | if (p[0] == 0xFE && p[1] == 0xED && p[2] == 0x1D && | ||
798 | p[3] < sizeof(params)) { | ||
799 | v = params[p[3]]; | ||
800 | put_unaligned(cpu_to_le32(v), (s32 *)p); | ||
801 | p += 4; | ||
802 | } else { | ||
803 | p++; | ||
804 | } | ||
805 | } | ||
806 | |||
807 | rc = 0; | ||
808 | |||
809 | cleanup: | ||
810 | kfree(buf); | ||
811 | return rc; | ||
812 | } | ||
813 | |||
629 | static int uclogic_probe(struct hid_device *hdev, | 814 | static int uclogic_probe(struct hid_device *hdev, |
630 | const struct hid_device_id *id) | 815 | const struct hid_device_id *id) |
631 | { | 816 | { |
632 | int rc; | 817 | int rc; |
818 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
819 | struct uclogic_drvdata *drvdata; | ||
633 | 820 | ||
634 | /* | 821 | /* |
635 | * libinput requires the pad interface to be on a different node | 822 | * libinput requires the pad interface to be on a different node |
@@ -637,6 +824,26 @@ static int uclogic_probe(struct hid_device *hdev, | |||
637 | */ | 824 | */ |
638 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | 825 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
639 | 826 | ||
827 | /* Allocate and assign driver data */ | ||
828 | drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); | ||
829 | if (drvdata == NULL) | ||
830 | return -ENOMEM; | ||
831 | |||
832 | hid_set_drvdata(hdev, drvdata); | ||
833 | |||
834 | switch (id->product) { | ||
835 | case USB_DEVICE_ID_HUION_TABLET: | ||
836 | /* If this is the pen interface */ | ||
837 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { | ||
838 | rc = uclogic_tablet_enable(hdev); | ||
839 | if (rc) { | ||
840 | hid_err(hdev, "tablet enabling failed\n"); | ||
841 | return rc; | ||
842 | } | ||
843 | } | ||
844 | break; | ||
845 | } | ||
846 | |||
640 | rc = hid_parse(hdev); | 847 | rc = hid_parse(hdev); |
641 | if (rc) { | 848 | if (rc) { |
642 | hid_err(hdev, "parse failed\n"); | 849 | hid_err(hdev, "parse failed\n"); |
@@ -652,6 +859,21 @@ static int uclogic_probe(struct hid_device *hdev, | |||
652 | return 0; | 859 | return 0; |
653 | } | 860 | } |
654 | 861 | ||
862 | static int uclogic_raw_event(struct hid_device *hdev, struct hid_report *report, | ||
863 | u8 *data, int size) | ||
864 | { | ||
865 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
866 | |||
867 | /* If this is a pen input report */ | ||
868 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0 && | ||
869 | report->type == HID_INPUT_REPORT && | ||
870 | report->id == 0x07 && size >= 2) | ||
871 | /* Invert the in-range bit */ | ||
872 | data[1] ^= 0x40; | ||
873 | |||
874 | return 0; | ||
875 | } | ||
876 | |||
655 | static const struct hid_device_id uclogic_devices[] = { | 877 | static const struct hid_device_id uclogic_devices[] = { |
656 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, | 878 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, |
657 | USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, | 879 | USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, |
@@ -667,6 +889,8 @@ static const struct hid_device_id uclogic_devices[] = { | |||
667 | USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, | 889 | USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, |
668 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, | 890 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, |
669 | USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) }, | 891 | USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) }, |
892 | { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) }, | ||
893 | { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) }, | ||
670 | { } | 894 | { } |
671 | }; | 895 | }; |
672 | MODULE_DEVICE_TABLE(hid, uclogic_devices); | 896 | MODULE_DEVICE_TABLE(hid, uclogic_devices); |
@@ -676,7 +900,10 @@ static struct hid_driver uclogic_driver = { | |||
676 | .id_table = uclogic_devices, | 900 | .id_table = uclogic_devices, |
677 | .probe = uclogic_probe, | 901 | .probe = uclogic_probe, |
678 | .report_fixup = uclogic_report_fixup, | 902 | .report_fixup = uclogic_report_fixup, |
903 | .raw_event = uclogic_raw_event, | ||
679 | }; | 904 | }; |
680 | module_hid_driver(uclogic_driver); | 905 | module_hid_driver(uclogic_driver); |
681 | 906 | ||
907 | MODULE_AUTHOR("Martin Rusko"); | ||
908 | MODULE_AUTHOR("Nikolai Kondrashov"); | ||
682 | MODULE_LICENSE("GPL"); | 909 | MODULE_LICENSE("GPL"); |