1 // SPDX-License-Identifier: GPL-2.0+
3 * HID driver for UC-Logic devices not fully compliant with HID standard
4 * - tablet initialization and parameter retrieval
6 * Copyright (c) 2018 Nikolai Kondrashov
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
16 #include "hid-uclogic-params.h"
17 #include "hid-uclogic-rdesc.h"
18 #include "usbhid/usbhid.h"
20 #include <linux/ctype.h>
21 #include <asm/unaligned.h>
24 * uclogic_params_pen_inrange_to_str() - Convert a pen in-range reporting type
27 * @inrange: The in-range reporting type to convert.
30 * The string representing the type, or NULL if the type is unknown.
32 const char *uclogic_params_pen_inrange_to_str(
33 enum uclogic_params_pen_inrange inrange)
36 case UCLOGIC_PARAMS_PEN_INRANGE_NORMAL:
38 case UCLOGIC_PARAMS_PEN_INRANGE_INVERTED:
40 case UCLOGIC_PARAMS_PEN_INRANGE_NONE:
48 * uclogic_params_get_str_desc - retrieve a string descriptor from a HID
49 * device interface, putting it into a kmalloc-allocated buffer as is, without
50 * character encoding conversion.
52 * @pbuf: Location for the kmalloc-allocated buffer pointer containing
53 * the retrieved descriptor. Not modified in case of error.
54 * Can be NULL to have retrieved descriptor discarded.
55 * @hdev: The HID device of the tablet interface to retrieve the string
56 * descriptor from. Cannot be NULL.
57 * @idx: Index of the string descriptor to request from the device.
58 * @len: Length of the buffer to allocate and the data to retrieve.
61 * number of bytes retrieved (<= len),
62 * -EPIPE, if the descriptor was not found, or
63 * another negative errno code in case of other error.
65 static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev,
69 struct usb_device *udev;
78 udev = hid_to_usb_dev(hdev);
80 buf = kmalloc(len, GFP_KERNEL);
86 rc = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
87 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
88 (USB_DT_STRING << 8) + idx,
90 USB_CTRL_GET_TIMEOUT);
92 hid_dbg(hdev, "string descriptor #%hhu not found\n", idx);
96 "failed retrieving string descriptor #%u: %d\n",
112 * uclogic_params_pen_cleanup - free resources used by struct
113 * uclogic_params_pen (tablet interface's pen input parameters).
114 * Can be called repeatedly.
116 * @pen: Pen input parameters to cleanup. Cannot be NULL.
118 static void uclogic_params_pen_cleanup(struct uclogic_params_pen *pen)
120 kfree(pen->desc_ptr);
121 memset(pen, 0, sizeof(*pen));
125 * uclogic_params_pen_init_v1() - initialize tablet interface pen
126 * input and retrieve its parameters from the device, using v1 protocol.
128 * @pen: Pointer to the pen parameters to initialize (to be
129 * cleaned up with uclogic_params_pen_cleanup()). Not modified in
130 * case of error, or if parameters are not found. Cannot be NULL.
131 * @pfound: Location for a flag which is set to true if the parameters
132 * were found, and to false if not (e.g. device was
133 * incompatible). Not modified in case of error. Cannot be NULL.
134 * @hdev: The HID device of the tablet interface to initialize and get
135 * parameters from. Cannot be NULL.
138 * Zero, if successful. A negative errno code on error.
140 static int uclogic_params_pen_init_v1(struct uclogic_params_pen *pen,
142 struct hid_device *hdev)
146 /* Buffer for (part of) the string descriptor */
148 /* Minimum descriptor length required, maximum seen so far is 18 */
151 /* Pen report descriptor template parameters */
152 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
153 __u8 *desc_ptr = NULL;
155 /* Check arguments */
156 if (pen == NULL || pfound == NULL || hdev == NULL) {
162 * Read string descriptor containing pen input parameters.
163 * The specific string descriptor and data were discovered by sniffing
164 * the Windows driver traffic.
165 * NOTE: This enables fully-functional tablet mode.
167 rc = uclogic_params_get_str_desc(&buf, hdev, 100, len);
170 "string descriptor with pen parameters not found, assuming not compatible\n");
173 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
175 } else if (rc != len) {
177 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
183 * Fill report descriptor parameters from the string descriptor
185 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
186 get_unaligned_le16(buf + 2);
187 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
188 get_unaligned_le16(buf + 4);
189 desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
190 get_unaligned_le16(buf + 8);
191 resolution = get_unaligned_le16(buf + 10);
192 if (resolution == 0) {
193 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
194 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
196 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
197 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
199 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
200 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
207 * Generate pen report descriptor
209 desc_ptr = uclogic_rdesc_template_apply(
210 uclogic_rdesc_v1_pen_template_arr,
211 uclogic_rdesc_v1_pen_template_size,
212 desc_params, ARRAY_SIZE(desc_params));
213 if (desc_ptr == NULL) {
219 * Fill-in the parameters
221 memset(pen, 0, sizeof(*pen));
222 pen->desc_ptr = desc_ptr;
224 pen->desc_size = uclogic_rdesc_v1_pen_template_size;
225 pen->id = UCLOGIC_RDESC_V1_PEN_ID;
226 pen->inrange = UCLOGIC_PARAMS_PEN_INRANGE_INVERTED;
238 * uclogic_params_get_le24() - get a 24-bit little-endian number from a
241 * @p: The pointer to the number buffer.
244 * The retrieved number
246 static s32 uclogic_params_get_le24(const void *p)
249 return b[0] | (b[1] << 8UL) | (b[2] << 16UL);
253 * uclogic_params_pen_init_v2() - initialize tablet interface pen
254 * input and retrieve its parameters from the device, using v2 protocol.
256 * @pen: Pointer to the pen parameters to initialize (to be
257 * cleaned up with uclogic_params_pen_cleanup()). Not modified in
258 * case of error, or if parameters are not found. Cannot be NULL.
259 * @pfound: Location for a flag which is set to true if the parameters
260 * were found, and to false if not (e.g. device was
261 * incompatible). Not modified in case of error. Cannot be NULL.
262 * @hdev: The HID device of the tablet interface to initialize and get
263 * parameters from. Cannot be NULL.
266 * Zero, if successful. A negative errno code on error.
268 static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen,
270 struct hid_device *hdev)
274 /* Buffer for (part of) the string descriptor */
276 /* Descriptor length required */
279 /* Pen report descriptor template parameters */
280 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
281 __u8 *desc_ptr = NULL;
283 /* Check arguments */
284 if (pen == NULL || pfound == NULL || hdev == NULL) {
290 * Read string descriptor containing pen input parameters.
291 * The specific string descriptor and data were discovered by sniffing
292 * the Windows driver traffic.
293 * NOTE: This enables fully-functional tablet mode.
295 rc = uclogic_params_get_str_desc(&buf, hdev, 200, len);
298 "string descriptor with pen parameters not found, assuming not compatible\n");
301 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
303 } else if (rc != len) {
305 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
311 * Check it's not just a catch-all UTF-16LE-encoded ASCII
312 * string (such as the model name) some tablets put into all
313 * unknown string descriptors.
317 (buf[i] >= 0x20 && buf[i] < 0x7f && buf[i + 1] == 0);
321 "string descriptor with pen parameters seems to contain only text, assuming not compatible\n");
327 * Fill report descriptor parameters from the string descriptor
329 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
330 uclogic_params_get_le24(buf + 2);
331 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
332 uclogic_params_get_le24(buf + 5);
333 desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
334 get_unaligned_le16(buf + 8);
335 resolution = get_unaligned_le16(buf + 10);
336 if (resolution == 0) {
337 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
338 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
340 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
341 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
343 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
344 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
351 * Generate pen report descriptor
353 desc_ptr = uclogic_rdesc_template_apply(
354 uclogic_rdesc_v2_pen_template_arr,
355 uclogic_rdesc_v2_pen_template_size,
356 desc_params, ARRAY_SIZE(desc_params));
357 if (desc_ptr == NULL) {
363 * Fill-in the parameters
365 memset(pen, 0, sizeof(*pen));
366 pen->desc_ptr = desc_ptr;
368 pen->desc_size = uclogic_rdesc_v2_pen_template_size;
369 pen->id = UCLOGIC_RDESC_V2_PEN_ID;
370 pen->inrange = UCLOGIC_PARAMS_PEN_INRANGE_NONE;
371 pen->fragmented_hires = true;
372 pen->tilt_y_flipped = true;
384 * uclogic_params_frame_cleanup - free resources used by struct
385 * uclogic_params_frame (tablet interface's frame controls input parameters).
386 * Can be called repeatedly.
388 * @frame: Frame controls input parameters to cleanup. Cannot be NULL.
390 static void uclogic_params_frame_cleanup(struct uclogic_params_frame *frame)
392 kfree(frame->desc_ptr);
393 memset(frame, 0, sizeof(*frame));
397 * uclogic_params_frame_init_with_desc() - initialize tablet's frame control
398 * parameters with a static report descriptor.
400 * @frame: Pointer to the frame parameters to initialize (to be cleaned
401 * up with uclogic_params_frame_cleanup()). Not modified in case
402 * of error. Cannot be NULL.
403 * @desc_ptr: Report descriptor pointer. Can be NULL, if desc_size is zero.
404 * @desc_size: Report descriptor size.
405 * @id: Report ID used for frame reports, if they should be tweaked,
409 * Zero, if successful. A negative errno code on error.
411 static int uclogic_params_frame_init_with_desc(
412 struct uclogic_params_frame *frame,
413 const __u8 *desc_ptr,
419 if (frame == NULL || (desc_ptr == NULL && desc_size != 0))
422 copy_desc_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
423 if (copy_desc_ptr == NULL)
426 memset(frame, 0, sizeof(*frame));
427 frame->desc_ptr = copy_desc_ptr;
428 frame->desc_size = desc_size;
434 * uclogic_params_frame_init_v1() - initialize v1 tablet interface frame
437 * @frame: Pointer to the frame parameters to initialize (to be cleaned
438 * up with uclogic_params_frame_cleanup()). Not modified in case
439 * of error, or if parameters are not found. Cannot be NULL.
440 * @pfound: Location for a flag which is set to true if the parameters
441 * were found, and to false if not (e.g. device was
442 * incompatible). Not modified in case of error. Cannot be NULL.
443 * @hdev: The HID device of the tablet interface to initialize and get
444 * parameters from. Cannot be NULL.
447 * Zero, if successful. A negative errno code on error.
449 static int uclogic_params_frame_init_v1(struct uclogic_params_frame *frame,
451 struct hid_device *hdev)
455 struct usb_device *usb_dev;
456 char *str_buf = NULL;
457 const size_t str_len = 16;
459 /* Check arguments */
460 if (frame == NULL || pfound == NULL || hdev == NULL) {
465 usb_dev = hid_to_usb_dev(hdev);
468 * Enable generic button mode
470 str_buf = kzalloc(str_len, GFP_KERNEL);
471 if (str_buf == NULL) {
476 rc = usb_string(usb_dev, 123, str_buf, str_len);
479 "generic button -enabling string descriptor not found\n");
482 } else if (strncmp(str_buf, "HK On", rc) != 0) {
484 "invalid response to enabling generic buttons: \"%s\"\n",
487 hid_dbg(hdev, "generic buttons enabled\n");
488 rc = uclogic_params_frame_init_with_desc(
490 uclogic_rdesc_v1_frame_arr,
491 uclogic_rdesc_v1_frame_size,
492 UCLOGIC_RDESC_V1_FRAME_ID);
506 * uclogic_params_cleanup - free resources used by struct uclogic_params
507 * (tablet interface's parameters).
508 * Can be called repeatedly.
510 * @params: Input parameters to cleanup. Cannot be NULL.
512 void uclogic_params_cleanup(struct uclogic_params *params)
514 if (!params->invalid) {
516 kfree(params->desc_ptr);
517 uclogic_params_pen_cleanup(¶ms->pen);
518 for (i = 0; i < ARRAY_SIZE(params->frame_list); i++)
519 uclogic_params_frame_cleanup(¶ms->frame_list[i]);
521 memset(params, 0, sizeof(*params));
526 * uclogic_params_get_desc() - Get a replacement report descriptor for a
527 * tablet's interface.
529 * @params: The parameters of a tablet interface to get report
530 * descriptor for. Cannot be NULL.
531 * @pdesc: Location for the resulting, kmalloc-allocated report
532 * descriptor pointer, or for NULL, if there's no replacement
533 * report descriptor. Not modified in case of error. Cannot be
535 * @psize: Location for the resulting report descriptor size, not set if
536 * there's no replacement report descriptor. Not modified in case
537 * of error. Cannot be NULL.
540 * Zero, if successful.
541 * -EINVAL, if invalid arguments are supplied.
542 * -ENOMEM, if failed to allocate memory.
544 int uclogic_params_get_desc(const struct uclogic_params *params,
549 bool present = false;
550 unsigned int size = 0;
554 /* Check arguments */
555 if (params == NULL || pdesc == NULL || psize == NULL)
558 /* Concatenate descriptors */
559 #define ADD_DESC(_desc_ptr, _desc_size) \
561 unsigned int new_size; \
563 if ((_desc_ptr) == NULL) { \
566 new_size = size + (_desc_size); \
567 new_desc = krealloc(desc, new_size, GFP_KERNEL); \
568 if (new_desc == NULL) { \
571 memcpy(new_desc + size, (_desc_ptr), (_desc_size)); \
577 ADD_DESC(params->desc_ptr, params->desc_size);
578 ADD_DESC(params->pen.desc_ptr, params->pen.desc_size);
579 for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) {
580 ADD_DESC(params->frame_list[i].desc_ptr,
581 params->frame_list[i].desc_size);
598 * uclogic_params_init_invalid() - initialize tablet interface parameters,
599 * specifying the interface is invalid.
601 * @params: Parameters to initialize (to be cleaned with
602 * uclogic_params_cleanup()). Cannot be NULL.
604 static void uclogic_params_init_invalid(struct uclogic_params *params)
606 params->invalid = true;
610 * uclogic_params_init_with_opt_desc() - initialize tablet interface
611 * parameters with an optional replacement report descriptor. Only modify
612 * report descriptor, if the original report descriptor matches the expected
615 * @params: Parameters to initialize (to be cleaned with
616 * uclogic_params_cleanup()). Not modified in case of
617 * error. Cannot be NULL.
618 * @hdev: The HID device of the tablet interface create the
619 * parameters for. Cannot be NULL.
620 * @orig_desc_size: Expected size of the original report descriptor to
622 * @desc_ptr: Pointer to the replacement report descriptor.
623 * Can be NULL, if desc_size is zero.
624 * @desc_size: Size of the replacement report descriptor.
627 * Zero, if successful. -EINVAL if an invalid argument was passed.
628 * -ENOMEM, if failed to allocate memory.
630 static int uclogic_params_init_with_opt_desc(struct uclogic_params *params,
631 struct hid_device *hdev,
632 unsigned int orig_desc_size,
634 unsigned int desc_size)
636 __u8 *desc_copy_ptr = NULL;
637 unsigned int desc_copy_size;
640 /* Check arguments */
641 if (params == NULL || hdev == NULL ||
642 (desc_ptr == NULL && desc_size != 0)) {
647 /* Replace report descriptor, if it matches */
648 if (hdev->dev_rsize == orig_desc_size) {
650 "device report descriptor matches the expected size, replacing\n");
651 desc_copy_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
652 if (desc_copy_ptr == NULL) {
656 desc_copy_size = desc_size;
659 "device report descriptor doesn't match the expected size (%u != %u), preserving\n",
660 hdev->dev_rsize, orig_desc_size);
661 desc_copy_ptr = NULL;
665 /* Output parameters */
666 memset(params, 0, sizeof(*params));
667 params->desc_ptr = desc_copy_ptr;
668 desc_copy_ptr = NULL;
669 params->desc_size = desc_copy_size;
673 kfree(desc_copy_ptr);
678 * uclogic_params_huion_init() - initialize a Huion tablet interface and discover
681 * @params: Parameters to fill in (to be cleaned with
682 * uclogic_params_cleanup()). Not modified in case of error.
684 * @hdev: The HID device of the tablet interface to initialize and get
685 * parameters from. Cannot be NULL.
688 * Zero, if successful. A negative errno code on error.
690 static int uclogic_params_huion_init(struct uclogic_params *params,
691 struct hid_device *hdev)
694 struct usb_device *udev;
695 struct usb_interface *iface;
696 __u8 bInterfaceNumber;
698 /* The resulting parameters (noop) */
699 struct uclogic_params p = {0, };
700 static const char transition_ver[] = "HUION_T153_160607";
701 char *ver_ptr = NULL;
702 const size_t ver_len = sizeof(transition_ver) + 1;
704 /* Check arguments */
705 if (params == NULL || hdev == NULL) {
710 udev = hid_to_usb_dev(hdev);
711 iface = to_usb_interface(hdev->dev.parent);
712 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
714 /* If it's not a pen interface */
715 if (bInterfaceNumber != 0) {
716 uclogic_params_init_invalid(&p);
720 /* Try to get firmware version */
721 ver_ptr = kzalloc(ver_len, GFP_KERNEL);
722 if (ver_ptr == NULL) {
726 rc = usb_string(udev, 201, ver_ptr, ver_len);
731 "failed retrieving Huion firmware version: %d\n", rc);
735 /* If this is a transition firmware */
736 if (strcmp(ver_ptr, transition_ver) == 0) {
738 "transition firmware detected, not probing pen v2 parameters\n");
740 /* Try to probe v2 pen parameters */
741 rc = uclogic_params_pen_init_v2(&p.pen, &found, hdev);
744 "failed probing pen v2 parameters: %d\n", rc);
747 hid_dbg(hdev, "pen v2 parameters found\n");
748 /* Create v2 frame parameters */
749 rc = uclogic_params_frame_init_with_desc(
751 uclogic_rdesc_v2_frame_arr,
752 uclogic_rdesc_v2_frame_size,
753 UCLOGIC_RDESC_V2_FRAME_ID);
756 "failed creating v2 frame parameters: %d\n",
760 /* Link frame button subreports from pen reports */
761 p.pen.subreport_list[0].value = 0xe0;
762 p.pen.subreport_list[0].id =
763 UCLOGIC_RDESC_V2_FRAME_ID;
766 hid_dbg(hdev, "pen v2 parameters not found\n");
769 /* Try to probe v1 pen parameters */
770 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
773 "failed probing pen v1 parameters: %d\n", rc);
776 hid_dbg(hdev, "pen v1 parameters found\n");
777 /* Try to probe v1 frame */
778 rc = uclogic_params_frame_init_v1(&p.frame_list[0],
781 hid_err(hdev, "v1 frame probing failed: %d\n", rc);
784 hid_dbg(hdev, "frame v1 parameters%s found\n",
785 (found ? "" : " not"));
787 /* Link frame button subreports from pen reports */
788 p.pen.subreport_list[0].value = 0xe0;
789 p.pen.subreport_list[0].id =
790 UCLOGIC_RDESC_V1_FRAME_ID;
794 hid_dbg(hdev, "pen v1 parameters not found\n");
796 uclogic_params_init_invalid(&p);
799 /* Output parameters */
800 memcpy(params, &p, sizeof(*params));
801 memset(&p, 0, sizeof(p));
805 uclogic_params_cleanup(&p);
810 * uclogic_params_init() - initialize a tablet interface and discover its
813 * @params: Parameters to fill in (to be cleaned with
814 * uclogic_params_cleanup()). Not modified in case of error.
816 * @hdev: The HID device of the tablet interface to initialize and get
817 * parameters from. Cannot be NULL. Must be using the USB low-level
818 * driver, i.e. be an actual USB tablet.
821 * Zero, if successful. A negative errno code on error.
823 int uclogic_params_init(struct uclogic_params *params,
824 struct hid_device *hdev)
827 struct usb_device *udev;
829 struct usb_interface *iface;
830 __u8 bInterfaceNumber;
832 /* The resulting parameters (noop) */
833 struct uclogic_params p = {0, };
835 /* Check arguments */
836 if (params == NULL || hdev == NULL || !hid_is_usb(hdev)) {
841 udev = hid_to_usb_dev(hdev);
842 bNumInterfaces = udev->config->desc.bNumInterfaces;
843 iface = to_usb_interface(hdev->dev.parent);
844 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
847 * Set replacement report descriptor if the original matches the
848 * specified size. Otherwise keep interface unchanged.
850 #define WITH_OPT_DESC(_orig_desc_token, _new_desc_token) \
851 uclogic_params_init_with_opt_desc( \
853 UCLOGIC_RDESC_##_orig_desc_token##_SIZE, \
854 uclogic_rdesc_##_new_desc_token##_arr, \
855 uclogic_rdesc_##_new_desc_token##_size)
857 #define VID_PID(_vid, _pid) \
858 (((__u32)(_vid) << 16) | ((__u32)(_pid) & U16_MAX))
861 * Handle specific interfaces for specific tablets.
863 * Observe the following logic:
865 * If the interface is recognized as producing certain useful input:
866 * Mark interface as valid.
867 * Output interface parameters.
868 * Else, if the interface is recognized as *not* producing any useful
870 * Mark interface as invalid.
872 * Mark interface as valid.
873 * Output noop parameters.
875 * Rule of thumb: it is better to disable a broken interface than let
876 * it spew garbage input.
879 switch (VID_PID(hdev->vendor, hdev->product)) {
880 case VID_PID(USB_VENDOR_ID_UCLOGIC,
881 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209):
882 rc = WITH_OPT_DESC(PF1209_ORIG, pf1209_fixed);
886 case VID_PID(USB_VENDOR_ID_UCLOGIC,
887 USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U):
888 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp4030u_fixed);
892 case VID_PID(USB_VENDOR_ID_UCLOGIC,
893 USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U):
894 if (hdev->dev_rsize == UCLOGIC_RDESC_WP5540U_V2_ORIG_SIZE) {
895 if (bInterfaceNumber == 0) {
896 /* Try to probe v1 pen parameters */
897 rc = uclogic_params_pen_init_v1(&p.pen,
901 "pen probing failed: %d\n",
907 "pen parameters not found");
910 uclogic_params_init_invalid(&p);
913 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp5540u_fixed);
918 case VID_PID(USB_VENDOR_ID_UCLOGIC,
919 USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U):
920 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp8060u_fixed);
924 case VID_PID(USB_VENDOR_ID_UCLOGIC,
925 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062):
926 rc = WITH_OPT_DESC(WP1062_ORIG, wp1062_fixed);
930 case VID_PID(USB_VENDOR_ID_UCLOGIC,
931 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850):
932 switch (bInterfaceNumber) {
934 rc = WITH_OPT_DESC(TWHL850_ORIG0, twhl850_fixed0);
939 rc = WITH_OPT_DESC(TWHL850_ORIG1, twhl850_fixed1);
944 rc = WITH_OPT_DESC(TWHL850_ORIG2, twhl850_fixed2);
950 case VID_PID(USB_VENDOR_ID_UCLOGIC,
951 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60):
953 * If it is not a three-interface version, which is known to
954 * respond to initialization.
956 if (bNumInterfaces != 3) {
957 switch (bInterfaceNumber) {
959 rc = WITH_OPT_DESC(TWHA60_ORIG0,
965 rc = WITH_OPT_DESC(TWHA60_ORIG1,
974 case VID_PID(USB_VENDOR_ID_HUION,
975 USB_DEVICE_ID_HUION_TABLET):
976 case VID_PID(USB_VENDOR_ID_HUION,
977 USB_DEVICE_ID_HUION_TABLET2):
978 case VID_PID(USB_VENDOR_ID_UCLOGIC,
979 USB_DEVICE_ID_HUION_TABLET):
980 case VID_PID(USB_VENDOR_ID_UCLOGIC,
981 USB_DEVICE_ID_YIYNOVA_TABLET):
982 case VID_PID(USB_VENDOR_ID_UCLOGIC,
983 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_81):
984 case VID_PID(USB_VENDOR_ID_UCLOGIC,
985 USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3):
986 case VID_PID(USB_VENDOR_ID_UCLOGIC,
987 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_45):
988 case VID_PID(USB_VENDOR_ID_UCLOGIC,
989 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_47):
990 rc = uclogic_params_huion_init(&p, hdev);
994 case VID_PID(USB_VENDOR_ID_UGTIZER,
995 USB_DEVICE_ID_UGTIZER_TABLET_GP0610):
996 case VID_PID(USB_VENDOR_ID_UGTIZER,
997 USB_DEVICE_ID_UGTIZER_TABLET_GT5040):
998 case VID_PID(USB_VENDOR_ID_UGEE,
999 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540):
1000 case VID_PID(USB_VENDOR_ID_UGEE,
1001 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640):
1002 case VID_PID(USB_VENDOR_ID_UGEE,
1003 USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720):
1004 /* If this is the pen interface */
1005 if (bInterfaceNumber == 1) {
1006 /* Probe v1 pen parameters */
1007 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1009 hid_err(hdev, "pen probing failed: %d\n", rc);
1013 hid_warn(hdev, "pen parameters not found");
1014 uclogic_params_init_invalid(&p);
1017 uclogic_params_init_invalid(&p);
1020 case VID_PID(USB_VENDOR_ID_UGEE,
1021 USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01):
1022 /* If this is the pen and frame interface */
1023 if (bInterfaceNumber == 1) {
1024 /* Probe v1 pen parameters */
1025 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1027 hid_err(hdev, "pen probing failed: %d\n", rc);
1030 /* Initialize frame parameters */
1031 rc = uclogic_params_frame_init_with_desc(
1033 uclogic_rdesc_xppen_deco01_frame_arr,
1034 uclogic_rdesc_xppen_deco01_frame_size,
1039 uclogic_params_init_invalid(&p);
1042 case VID_PID(USB_VENDOR_ID_TRUST,
1043 USB_DEVICE_ID_TRUST_PANORA_TABLET):
1044 case VID_PID(USB_VENDOR_ID_UGEE,
1045 USB_DEVICE_ID_UGEE_TABLET_G5):
1046 /* Ignore non-pen interfaces */
1047 if (bInterfaceNumber != 1) {
1048 uclogic_params_init_invalid(&p);
1052 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1054 hid_err(hdev, "pen probing failed: %d\n", rc);
1057 rc = uclogic_params_frame_init_with_desc(
1059 uclogic_rdesc_ugee_g5_frame_arr,
1060 uclogic_rdesc_ugee_g5_frame_size,
1061 UCLOGIC_RDESC_UGEE_G5_FRAME_ID);
1064 "failed creating frame parameters: %d\n",
1068 p.frame_list[0].re_lsb =
1069 UCLOGIC_RDESC_UGEE_G5_FRAME_RE_LSB;
1070 p.frame_list[0].dev_id_byte =
1071 UCLOGIC_RDESC_UGEE_G5_FRAME_DEV_ID_BYTE;
1073 hid_warn(hdev, "pen parameters not found");
1074 uclogic_params_init_invalid(&p);
1078 case VID_PID(USB_VENDOR_ID_UGEE,
1079 USB_DEVICE_ID_UGEE_TABLET_EX07S):
1080 /* Ignore non-pen interfaces */
1081 if (bInterfaceNumber != 1) {
1082 uclogic_params_init_invalid(&p);
1086 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1088 hid_err(hdev, "pen probing failed: %d\n", rc);
1091 rc = uclogic_params_frame_init_with_desc(
1093 uclogic_rdesc_ugee_ex07_frame_arr,
1094 uclogic_rdesc_ugee_ex07_frame_size,
1098 "failed creating frame parameters: %d\n",
1103 hid_warn(hdev, "pen parameters not found");
1104 uclogic_params_init_invalid(&p);
1111 #undef WITH_OPT_DESC
1113 /* Output parameters */
1114 memcpy(params, &p, sizeof(*params));
1115 memset(&p, 0, sizeof(p));
1118 uclogic_params_cleanup(&p);