1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "hid-uclogic-params.h"
17#include "hid-uclogic-rdesc.h"
18#include "usbhid/usbhid.h"
19#include "hid-ids.h"
20#include <linux/ctype.h>
21#include <asm/unaligned.h>
22
23
24
25
26
27
28
29
30
31const char *uclogic_params_pen_inrange_to_str(
32 enum uclogic_params_pen_inrange inrange)
33{
34 switch (inrange) {
35 case UCLOGIC_PARAMS_PEN_INRANGE_NORMAL:
36 return "normal";
37 case UCLOGIC_PARAMS_PEN_INRANGE_INVERTED:
38 return "inverted";
39 case UCLOGIC_PARAMS_PEN_INRANGE_NONE:
40 return "none";
41 default:
42 return NULL;
43 }
44}
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev,
65 __u8 idx, size_t len)
66{
67 int rc;
68 struct usb_device *udev = hid_to_usb_dev(hdev);
69 __u8 *buf = NULL;
70
71
72 if (hdev == NULL) {
73 rc = -EINVAL;
74 goto cleanup;
75 }
76
77 buf = kmalloc(len, GFP_KERNEL);
78 if (buf == NULL) {
79 rc = -ENOMEM;
80 goto cleanup;
81 }
82
83 rc = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
84 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
85 (USB_DT_STRING << 8) + idx,
86 0x0409, buf, len,
87 USB_CTRL_GET_TIMEOUT);
88 if (rc == -EPIPE) {
89 hid_dbg(hdev, "string descriptor #%hhu not found\n", idx);
90 goto cleanup;
91 } else if (rc < 0) {
92 hid_err(hdev,
93 "failed retrieving string descriptor #%u: %d\n",
94 idx, rc);
95 goto cleanup;
96 }
97
98 if (pbuf != NULL) {
99 *pbuf = buf;
100 buf = NULL;
101 }
102
103cleanup:
104 kfree(buf);
105 return rc;
106}
107
108
109
110
111
112
113
114
115static void uclogic_params_pen_cleanup(struct uclogic_params_pen *pen)
116{
117 kfree(pen->desc_ptr);
118 memset(pen, 0, sizeof(*pen));
119}
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137static int uclogic_params_pen_init_v1(struct uclogic_params_pen *pen,
138 bool *pfound,
139 struct hid_device *hdev)
140{
141 int rc;
142 bool found = false;
143
144 __u8 *buf = NULL;
145
146 const int len = 12;
147 s32 resolution;
148
149 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
150 __u8 *desc_ptr = NULL;
151
152
153 if (pen == NULL || pfound == NULL || hdev == NULL) {
154 rc = -EINVAL;
155 goto cleanup;
156 }
157
158
159
160
161
162
163
164 rc = uclogic_params_get_str_desc(&buf, hdev, 100, len);
165 if (rc == -EPIPE) {
166 hid_dbg(hdev,
167 "string descriptor with pen parameters not found, assuming not compatible\n");
168 goto finish;
169 } else if (rc < 0) {
170 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
171 goto cleanup;
172 } else if (rc != len) {
173 hid_dbg(hdev,
174 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
175 rc, len);
176 goto finish;
177 }
178
179
180
181
182 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
183 get_unaligned_le16(buf + 2);
184 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
185 get_unaligned_le16(buf + 4);
186 desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
187 get_unaligned_le16(buf + 8);
188 resolution = get_unaligned_le16(buf + 10);
189 if (resolution == 0) {
190 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
191 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
192 } else {
193 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
194 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
195 resolution;
196 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
197 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
198 resolution;
199 }
200 kfree(buf);
201 buf = NULL;
202
203
204
205
206 desc_ptr = uclogic_rdesc_template_apply(
207 uclogic_rdesc_pen_v1_template_arr,
208 uclogic_rdesc_pen_v1_template_size,
209 desc_params, ARRAY_SIZE(desc_params));
210 if (desc_ptr == NULL) {
211 rc = -ENOMEM;
212 goto cleanup;
213 }
214
215
216
217
218 memset(pen, 0, sizeof(*pen));
219 pen->desc_ptr = desc_ptr;
220 desc_ptr = NULL;
221 pen->desc_size = uclogic_rdesc_pen_v1_template_size;
222 pen->id = UCLOGIC_RDESC_PEN_V1_ID;
223 pen->inrange = UCLOGIC_PARAMS_PEN_INRANGE_INVERTED;
224 found = true;
225finish:
226 *pfound = found;
227 rc = 0;
228cleanup:
229 kfree(desc_ptr);
230 kfree(buf);
231 return rc;
232}
233
234
235
236
237
238
239
240
241
242
243static s32 uclogic_params_get_le24(const void *p)
244{
245 const __u8 *b = p;
246 return b[0] | (b[1] << 8UL) | (b[2] << 16UL);
247}
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen,
266 bool *pfound,
267 struct hid_device *hdev)
268{
269 int rc;
270 bool found = false;
271
272 __u8 *buf = NULL;
273
274 const int len = 18;
275 s32 resolution;
276
277 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
278 __u8 *desc_ptr = NULL;
279
280
281 if (pen == NULL || pfound == NULL || hdev == NULL) {
282 rc = -EINVAL;
283 goto cleanup;
284 }
285
286
287
288
289
290
291
292 rc = uclogic_params_get_str_desc(&buf, hdev, 200, len);
293 if (rc == -EPIPE) {
294 hid_dbg(hdev,
295 "string descriptor with pen parameters not found, assuming not compatible\n");
296 goto finish;
297 } else if (rc < 0) {
298 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
299 goto cleanup;
300 } else if (rc != len) {
301 hid_dbg(hdev,
302 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
303 rc, len);
304 goto finish;
305 } else {
306 size_t i;
307
308
309
310
311
312 for (i = 2;
313 i < len &&
314 (buf[i] >= 0x20 && buf[i] < 0x7f && buf[i + 1] == 0);
315 i += 2);
316 if (i >= len) {
317 hid_dbg(hdev,
318 "string descriptor with pen parameters seems to contain only text, assuming not compatible\n");
319 goto finish;
320 }
321 }
322
323
324
325
326 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
327 uclogic_params_get_le24(buf + 2);
328 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
329 uclogic_params_get_le24(buf + 5);
330 desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
331 get_unaligned_le16(buf + 8);
332 resolution = get_unaligned_le16(buf + 10);
333 if (resolution == 0) {
334 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
335 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
336 } else {
337 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
338 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
339 resolution;
340 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
341 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
342 resolution;
343 }
344 kfree(buf);
345 buf = NULL;
346
347
348
349
350 desc_ptr = uclogic_rdesc_template_apply(
351 uclogic_rdesc_pen_v2_template_arr,
352 uclogic_rdesc_pen_v2_template_size,
353 desc_params, ARRAY_SIZE(desc_params));
354 if (desc_ptr == NULL) {
355 rc = -ENOMEM;
356 goto cleanup;
357 }
358
359
360
361
362 memset(pen, 0, sizeof(*pen));
363 pen->desc_ptr = desc_ptr;
364 desc_ptr = NULL;
365 pen->desc_size = uclogic_rdesc_pen_v2_template_size;
366 pen->id = UCLOGIC_RDESC_PEN_V2_ID;
367 pen->inrange = UCLOGIC_PARAMS_PEN_INRANGE_NONE;
368 pen->fragmented_hires = true;
369 found = true;
370finish:
371 *pfound = found;
372 rc = 0;
373cleanup:
374 kfree(desc_ptr);
375 kfree(buf);
376 return rc;
377}
378
379
380
381
382
383
384
385
386static void uclogic_params_frame_cleanup(struct uclogic_params_frame *frame)
387{
388 kfree(frame->desc_ptr);
389 memset(frame, 0, sizeof(*frame));
390}
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407static int uclogic_params_frame_init_with_desc(
408 struct uclogic_params_frame *frame,
409 const __u8 *desc_ptr,
410 size_t desc_size,
411 unsigned int id)
412{
413 __u8 *copy_desc_ptr;
414
415 if (frame == NULL || (desc_ptr == NULL && desc_size != 0))
416 return -EINVAL;
417
418 copy_desc_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
419 if (copy_desc_ptr == NULL)
420 return -ENOMEM;
421
422 memset(frame, 0, sizeof(*frame));
423 frame->desc_ptr = copy_desc_ptr;
424 frame->desc_size = desc_size;
425 frame->id = id;
426 return 0;
427}
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445static int uclogic_params_frame_init_v1_buttonpad(
446 struct uclogic_params_frame *frame,
447 bool *pfound,
448 struct hid_device *hdev)
449{
450 int rc;
451 bool found = false;
452 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
453 char *str_buf = NULL;
454 const size_t str_len = 16;
455
456
457 if (frame == NULL || pfound == NULL || hdev == NULL) {
458 rc = -EINVAL;
459 goto cleanup;
460 }
461
462
463
464
465 str_buf = kzalloc(str_len, GFP_KERNEL);
466 if (str_buf == NULL) {
467 rc = -ENOMEM;
468 goto cleanup;
469 }
470
471 rc = usb_string(usb_dev, 123, str_buf, str_len);
472 if (rc == -EPIPE) {
473 hid_dbg(hdev,
474 "generic button -enabling string descriptor not found\n");
475 } else if (rc < 0) {
476 goto cleanup;
477 } else if (strncmp(str_buf, "HK On", rc) != 0) {
478 hid_dbg(hdev,
479 "invalid response to enabling generic buttons: \"%s\"\n",
480 str_buf);
481 } else {
482 hid_dbg(hdev, "generic buttons enabled\n");
483 rc = uclogic_params_frame_init_with_desc(
484 frame,
485 uclogic_rdesc_buttonpad_v1_arr,
486 uclogic_rdesc_buttonpad_v1_size,
487 UCLOGIC_RDESC_BUTTONPAD_V1_ID);
488 if (rc != 0)
489 goto cleanup;
490 found = true;
491 }
492
493 *pfound = found;
494 rc = 0;
495cleanup:
496 kfree(str_buf);
497 return rc;
498}
499
500
501
502
503
504
505
506
507void uclogic_params_cleanup(struct uclogic_params *params)
508{
509 if (!params->invalid) {
510 kfree(params->desc_ptr);
511 if (!params->pen_unused)
512 uclogic_params_pen_cleanup(¶ms->pen);
513 uclogic_params_frame_cleanup(¶ms->frame);
514 memset(params, 0, sizeof(*params));
515 }
516}
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536int uclogic_params_get_desc(const struct uclogic_params *params,
537 __u8 **pdesc,
538 unsigned int *psize)
539{
540 bool common_present;
541 bool pen_present;
542 bool frame_present;
543 unsigned int size;
544 __u8 *desc = NULL;
545
546
547 if (params == NULL || pdesc == NULL || psize == NULL)
548 return -EINVAL;
549
550 size = 0;
551
552 common_present = (params->desc_ptr != NULL);
553 pen_present = (!params->pen_unused && params->pen.desc_ptr != NULL);
554 frame_present = (params->frame.desc_ptr != NULL);
555
556 if (common_present)
557 size += params->desc_size;
558 if (pen_present)
559 size += params->pen.desc_size;
560 if (frame_present)
561 size += params->frame.desc_size;
562
563 if (common_present || pen_present || frame_present) {
564 __u8 *p;
565
566 desc = kmalloc(size, GFP_KERNEL);
567 if (desc == NULL)
568 return -ENOMEM;
569 p = desc;
570
571 if (common_present) {
572 memcpy(p, params->desc_ptr,
573 params->desc_size);
574 p += params->desc_size;
575 }
576 if (pen_present) {
577 memcpy(p, params->pen.desc_ptr,
578 params->pen.desc_size);
579 p += params->pen.desc_size;
580 }
581 if (frame_present) {
582 memcpy(p, params->frame.desc_ptr,
583 params->frame.desc_size);
584 p += params->frame.desc_size;
585 }
586
587 WARN_ON(p != desc + size);
588
589 *psize = size;
590 }
591
592 *pdesc = desc;
593 return 0;
594}
595
596
597
598
599
600
601
602
603static void uclogic_params_init_invalid(struct uclogic_params *params)
604{
605 params->invalid = true;
606}
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629static int uclogic_params_init_with_opt_desc(struct uclogic_params *params,
630 struct hid_device *hdev,
631 unsigned int orig_desc_size,
632 __u8 *desc_ptr,
633 unsigned int desc_size)
634{
635 __u8 *desc_copy_ptr = NULL;
636 unsigned int desc_copy_size;
637 int rc;
638
639
640 if (params == NULL || hdev == NULL ||
641 (desc_ptr == NULL && desc_size != 0)) {
642 rc = -EINVAL;
643 goto cleanup;
644 }
645
646
647 if (hdev->dev_rsize == orig_desc_size) {
648 hid_dbg(hdev,
649 "device report descriptor matches the expected size, replacing\n");
650 desc_copy_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
651 if (desc_copy_ptr == NULL) {
652 rc = -ENOMEM;
653 goto cleanup;
654 }
655 desc_copy_size = desc_size;
656 } else {
657 hid_dbg(hdev,
658 "device report descriptor doesn't match the expected size (%u != %u), preserving\n",
659 hdev->dev_rsize, orig_desc_size);
660 desc_copy_ptr = NULL;
661 desc_copy_size = 0;
662 }
663
664
665 memset(params, 0, sizeof(*params));
666 params->desc_ptr = desc_copy_ptr;
667 desc_copy_ptr = NULL;
668 params->desc_size = desc_copy_size;
669
670 rc = 0;
671cleanup:
672 kfree(desc_copy_ptr);
673 return rc;
674}
675
676
677
678
679
680
681
682
683
684
685static void uclogic_params_init_with_pen_unused(struct uclogic_params *params)
686{
687 memset(params, 0, sizeof(*params));
688 params->pen_unused = true;
689}
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704static int uclogic_params_huion_init(struct uclogic_params *params,
705 struct hid_device *hdev)
706{
707 int rc;
708 struct usb_device *udev = hid_to_usb_dev(hdev);
709 struct usb_interface *iface = to_usb_interface(hdev->dev.parent);
710 __u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
711 bool found;
712
713 struct uclogic_params p = {0, };
714 static const char transition_ver[] = "HUION_T153_160607";
715 char *ver_ptr = NULL;
716 const size_t ver_len = sizeof(transition_ver) + 1;
717
718
719 if (params == NULL || hdev == NULL) {
720 rc = -EINVAL;
721 goto cleanup;
722 }
723
724
725 if (bInterfaceNumber != 0) {
726
727 uclogic_params_init_with_pen_unused(&p);
728 goto output;
729 }
730
731
732 ver_ptr = kzalloc(ver_len, GFP_KERNEL);
733 if (ver_ptr == NULL) {
734 rc = -ENOMEM;
735 goto cleanup;
736 }
737 rc = usb_string(udev, 201, ver_ptr, ver_len);
738 if (rc == -EPIPE) {
739 *ver_ptr = '\0';
740 } else if (rc < 0) {
741 hid_err(hdev,
742 "failed retrieving Huion firmware version: %d\n", rc);
743 goto cleanup;
744 }
745
746
747 if (strcmp(ver_ptr, transition_ver) == 0) {
748 hid_dbg(hdev,
749 "transition firmware detected, not probing pen v2 parameters\n");
750 } else {
751
752 rc = uclogic_params_pen_init_v2(&p.pen, &found, hdev);
753 if (rc != 0) {
754 hid_err(hdev,
755 "failed probing pen v2 parameters: %d\n", rc);
756 goto cleanup;
757 } else if (found) {
758 hid_dbg(hdev, "pen v2 parameters found\n");
759
760 rc = uclogic_params_frame_init_with_desc(
761 &p.frame,
762 uclogic_rdesc_buttonpad_v2_arr,
763 uclogic_rdesc_buttonpad_v2_size,
764 UCLOGIC_RDESC_BUTTONPAD_V2_ID);
765 if (rc != 0) {
766 hid_err(hdev,
767 "failed creating v2 buttonpad parameters: %d\n",
768 rc);
769 goto cleanup;
770 }
771
772 p.pen_frame_flag = 0x20;
773 goto output;
774 }
775 hid_dbg(hdev, "pen v2 parameters not found\n");
776 }
777
778
779 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
780 if (rc != 0) {
781 hid_err(hdev,
782 "failed probing pen v1 parameters: %d\n", rc);
783 goto cleanup;
784 } else if (found) {
785 hid_dbg(hdev, "pen v1 parameters found\n");
786
787 rc = uclogic_params_frame_init_v1_buttonpad(
788 &p.frame,
789 &found, hdev);
790 if (rc != 0) {
791 hid_err(hdev, "v1 buttonpad probing failed: %d\n", rc);
792 goto cleanup;
793 }
794 hid_dbg(hdev, "buttonpad v1 parameters%s found\n",
795 (found ? "" : " not"));
796 if (found) {
797
798 p.pen_frame_flag = 0x20;
799 }
800 goto output;
801 }
802 hid_dbg(hdev, "pen v1 parameters not found\n");
803
804 uclogic_params_init_invalid(&p);
805
806output:
807
808 memcpy(params, &p, sizeof(*params));
809 memset(&p, 0, sizeof(p));
810 rc = 0;
811cleanup:
812 kfree(ver_ptr);
813 uclogic_params_cleanup(&p);
814 return rc;
815}
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831int uclogic_params_init(struct uclogic_params *params,
832 struct hid_device *hdev)
833{
834 int rc;
835 struct usb_device *udev = hid_to_usb_dev(hdev);
836 __u8 bNumInterfaces = udev->config->desc.bNumInterfaces;
837 struct usb_interface *iface = to_usb_interface(hdev->dev.parent);
838 __u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
839 bool found;
840
841 struct uclogic_params p = {0, };
842
843
844 if (params == NULL || hdev == NULL ||
845 !hid_is_using_ll_driver(hdev, &usb_hid_driver)) {
846 rc = -EINVAL;
847 goto cleanup;
848 }
849
850
851
852
853
854#define WITH_OPT_DESC(_orig_desc_token, _new_desc_token) \
855 uclogic_params_init_with_opt_desc( \
856 &p, hdev, \
857 UCLOGIC_RDESC_##_orig_desc_token##_SIZE, \
858 uclogic_rdesc_##_new_desc_token##_arr, \
859 uclogic_rdesc_##_new_desc_token##_size)
860
861#define VID_PID(_vid, _pid) \
862 (((__u32)(_vid) << 16) | ((__u32)(_pid) & U16_MAX))
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883 switch (VID_PID(hdev->vendor, hdev->product)) {
884 case VID_PID(USB_VENDOR_ID_UCLOGIC,
885 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209):
886 rc = WITH_OPT_DESC(PF1209_ORIG, pf1209_fixed);
887 if (rc != 0)
888 goto cleanup;
889 break;
890 case VID_PID(USB_VENDOR_ID_UCLOGIC,
891 USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U):
892 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp4030u_fixed);
893 if (rc != 0)
894 goto cleanup;
895 break;
896 case VID_PID(USB_VENDOR_ID_UCLOGIC,
897 USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U):
898 if (hdev->dev_rsize == UCLOGIC_RDESC_WP5540U_V2_ORIG_SIZE) {
899 if (bInterfaceNumber == 0) {
900
901 rc = uclogic_params_pen_init_v1(&p.pen,
902 &found, hdev);
903 if (rc != 0) {
904 hid_err(hdev,
905 "pen probing failed: %d\n",
906 rc);
907 goto cleanup;
908 }
909 if (!found) {
910 hid_warn(hdev,
911 "pen parameters not found");
912 }
913 } else {
914 uclogic_params_init_invalid(&p);
915 }
916 } else {
917 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp5540u_fixed);
918 if (rc != 0)
919 goto cleanup;
920 }
921 break;
922 case VID_PID(USB_VENDOR_ID_UCLOGIC,
923 USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U):
924 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp8060u_fixed);
925 if (rc != 0)
926 goto cleanup;
927 break;
928 case VID_PID(USB_VENDOR_ID_UCLOGIC,
929 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062):
930 rc = WITH_OPT_DESC(WP1062_ORIG, wp1062_fixed);
931 if (rc != 0)
932 goto cleanup;
933 break;
934 case VID_PID(USB_VENDOR_ID_UCLOGIC,
935 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850):
936 switch (bInterfaceNumber) {
937 case 0:
938 rc = WITH_OPT_DESC(TWHL850_ORIG0, twhl850_fixed0);
939 if (rc != 0)
940 goto cleanup;
941 break;
942 case 1:
943 rc = WITH_OPT_DESC(TWHL850_ORIG1, twhl850_fixed1);
944 if (rc != 0)
945 goto cleanup;
946 break;
947 case 2:
948 rc = WITH_OPT_DESC(TWHL850_ORIG2, twhl850_fixed2);
949 if (rc != 0)
950 goto cleanup;
951 break;
952 }
953 break;
954 case VID_PID(USB_VENDOR_ID_UCLOGIC,
955 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60):
956
957
958
959
960 if (bNumInterfaces != 3) {
961 switch (bInterfaceNumber) {
962 case 0:
963 rc = WITH_OPT_DESC(TWHA60_ORIG0,
964 twha60_fixed0);
965 if (rc != 0)
966 goto cleanup;
967 break;
968 case 1:
969 rc = WITH_OPT_DESC(TWHA60_ORIG1,
970 twha60_fixed1);
971 if (rc != 0)
972 goto cleanup;
973 break;
974 }
975 break;
976 }
977 fallthrough;
978 case VID_PID(USB_VENDOR_ID_HUION,
979 USB_DEVICE_ID_HUION_TABLET):
980 case VID_PID(USB_VENDOR_ID_HUION,
981 USB_DEVICE_ID_HUION_HS64):
982 case VID_PID(USB_VENDOR_ID_UCLOGIC,
983 USB_DEVICE_ID_HUION_TABLET):
984 case VID_PID(USB_VENDOR_ID_UCLOGIC,
985 USB_DEVICE_ID_YIYNOVA_TABLET):
986 case VID_PID(USB_VENDOR_ID_UCLOGIC,
987 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_81):
988 case VID_PID(USB_VENDOR_ID_UCLOGIC,
989 USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3):
990 case VID_PID(USB_VENDOR_ID_UCLOGIC,
991 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_45):
992 case VID_PID(USB_VENDOR_ID_UCLOGIC,
993 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_47):
994 rc = uclogic_params_huion_init(&p, hdev);
995 if (rc != 0)
996 goto cleanup;
997 break;
998 case VID_PID(USB_VENDOR_ID_UGTIZER,
999 USB_DEVICE_ID_UGTIZER_TABLET_GP0610):
1000 case VID_PID(USB_VENDOR_ID_UGTIZER,
1001 USB_DEVICE_ID_UGTIZER_TABLET_GT5040):
1002 case VID_PID(USB_VENDOR_ID_UGEE,
1003 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540):
1004 case VID_PID(USB_VENDOR_ID_UGEE,
1005 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640):
1006 case VID_PID(USB_VENDOR_ID_UGEE,
1007 USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720):
1008
1009 if (bInterfaceNumber == 1) {
1010
1011 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1012 if (rc != 0) {
1013 hid_err(hdev, "pen probing failed: %d\n", rc);
1014 goto cleanup;
1015 }
1016 if (!found) {
1017 hid_warn(hdev, "pen parameters not found");
1018 uclogic_params_init_invalid(&p);
1019 }
1020 } else {
1021
1022 uclogic_params_init_with_pen_unused(&p);
1023 }
1024 break;
1025 case VID_PID(USB_VENDOR_ID_UGEE,
1026 USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01):
1027
1028 if (bInterfaceNumber == 1) {
1029
1030 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1031 if (rc != 0) {
1032 hid_err(hdev, "pen probing failed: %d\n", rc);
1033 goto cleanup;
1034 }
1035
1036 rc = uclogic_params_frame_init_with_desc(
1037 &p.frame,
1038 uclogic_rdesc_xppen_deco01_frame_arr,
1039 uclogic_rdesc_xppen_deco01_frame_size,
1040 0);
1041 if (rc != 0)
1042 goto cleanup;
1043 } else {
1044
1045 uclogic_params_init_with_pen_unused(&p);
1046 }
1047 break;
1048 case VID_PID(USB_VENDOR_ID_UGEE,
1049 USB_DEVICE_ID_UGEE_TABLET_G5):
1050
1051 if (bInterfaceNumber != 1) {
1052 uclogic_params_init_invalid(&p);
1053 break;
1054 }
1055
1056 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1057 if (rc != 0) {
1058 hid_err(hdev, "pen probing failed: %d\n", rc);
1059 goto cleanup;
1060 } else if (found) {
1061 rc = uclogic_params_frame_init_with_desc(
1062 &p.frame,
1063 uclogic_rdesc_ugee_g5_frame_arr,
1064 uclogic_rdesc_ugee_g5_frame_size,
1065 UCLOGIC_RDESC_UGEE_G5_FRAME_ID);
1066 if (rc != 0) {
1067 hid_err(hdev,
1068 "failed creating buttonpad parameters: %d\n",
1069 rc);
1070 goto cleanup;
1071 }
1072 p.frame.re_lsb =
1073 UCLOGIC_RDESC_UGEE_G5_FRAME_RE_LSB;
1074 p.frame.dev_id_byte =
1075 UCLOGIC_RDESC_UGEE_G5_FRAME_DEV_ID_BYTE;
1076 } else {
1077 hid_warn(hdev, "pen parameters not found");
1078 uclogic_params_init_invalid(&p);
1079 }
1080
1081 break;
1082 case VID_PID(USB_VENDOR_ID_UGEE,
1083 USB_DEVICE_ID_UGEE_TABLET_EX07S):
1084
1085 if (bInterfaceNumber != 1) {
1086 uclogic_params_init_invalid(&p);
1087 break;
1088 }
1089
1090 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1091 if (rc != 0) {
1092 hid_err(hdev, "pen probing failed: %d\n", rc);
1093 goto cleanup;
1094 } else if (found) {
1095 rc = uclogic_params_frame_init_with_desc(
1096 &p.frame,
1097 uclogic_rdesc_ugee_ex07_buttonpad_arr,
1098 uclogic_rdesc_ugee_ex07_buttonpad_size,
1099 0);
1100 if (rc != 0) {
1101 hid_err(hdev,
1102 "failed creating buttonpad parameters: %d\n",
1103 rc);
1104 goto cleanup;
1105 }
1106 } else {
1107 hid_warn(hdev, "pen parameters not found");
1108 uclogic_params_init_invalid(&p);
1109 }
1110
1111 break;
1112 }
1113
1114#undef VID_PID
1115#undef WITH_OPT_DESC
1116
1117
1118 memcpy(params, &p, sizeof(*params));
1119 memset(&p, 0, sizeof(p));
1120 rc = 0;
1121cleanup:
1122 uclogic_params_cleanup(&p);
1123 return rc;
1124}
1125