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 * Convert a pen in-range reporting type to a string.
26 * @inrange: The in-range reporting type to convert.
29 * The string representing the type, or NULL if the type is unknown.
31 const char *uclogic_params_pen_inrange_to_str(
32 enum uclogic_params_pen_inrange inrange)
35 case UCLOGIC_PARAMS_PEN_INRANGE_NORMAL:
37 case UCLOGIC_PARAMS_PEN_INRANGE_INVERTED:
39 case UCLOGIC_PARAMS_PEN_INRANGE_NONE:
47 * uclogic_params_get_str_desc - retrieve a string descriptor from a HID
48 * device interface, putting it into a kmalloc-allocated buffer as is, without
49 * character encoding conversion.
51 * @pbuf: Location for the kmalloc-allocated buffer pointer containing
52 * the retrieved descriptor. Not modified in case of error.
53 * Can be NULL to have retrieved descriptor discarded.
54 * @hdev: The HID device of the tablet interface to retrieve the string
55 * descriptor from. Cannot be NULL.
56 * @idx: Index of the string descriptor to request from the device.
57 * @len: Length of the buffer to allocate and the data to retrieve.
60 * number of bytes retrieved (<= len),
61 * -EPIPE, if the descriptor was not found, or
62 * another negative errno code in case of other error.
64 static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev,
68 struct usb_device *udev = hid_to_usb_dev(hdev);
77 buf = kmalloc(len, GFP_KERNEL);
83 rc = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
84 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
85 (USB_DT_STRING << 8) + idx,
87 USB_CTRL_GET_TIMEOUT);
89 hid_dbg(hdev, "string descriptor #%hhu not found\n", idx);
93 "failed retrieving string descriptor #%hhu: %d\n",
109 * uclogic_params_pen_cleanup - free resources used by struct
110 * uclogic_params_pen (tablet interface's pen input parameters).
111 * Can be called repeatedly.
113 * @pen: Pen input parameters to cleanup. Cannot be NULL.
115 static void uclogic_params_pen_cleanup(struct uclogic_params_pen *pen)
117 kfree(pen->desc_ptr);
118 memset(pen, 0, sizeof(*pen));
122 * uclogic_params_pen_init_v1() - initialize tablet interface pen
123 * input and retrieve its parameters from the device, using v1 protocol.
125 * @pen: Pointer to the pen parameters to initialize (to be
126 * cleaned up with uclogic_params_pen_cleanup()). Not modified in
127 * case of error, or if parameters are not found. Cannot be NULL.
128 * @pfound: Location for a flag which is set to true if the parameters
129 * were found, and to false if not (e.g. device was
130 * incompatible). Not modified in case of error. Cannot be NULL.
131 * @hdev: The HID device of the tablet interface to initialize and get
132 * parameters from. Cannot be NULL.
135 * Zero, if successful. A negative errno code on error.
137 static int uclogic_params_pen_init_v1(struct uclogic_params_pen *pen,
139 struct hid_device *hdev)
143 /* Buffer for (part of) the string descriptor */
145 /* Minimum descriptor length required, maximum seen so far is 18 */
148 /* Pen report descriptor template parameters */
149 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
150 __u8 *desc_ptr = NULL;
152 /* Check arguments */
153 if (pen == NULL || pfound == NULL || hdev == NULL) {
159 * Read string descriptor containing pen input parameters.
160 * The specific string descriptor and data were discovered by sniffing
161 * the Windows driver traffic.
162 * NOTE: This enables fully-functional tablet mode.
164 rc = uclogic_params_get_str_desc(&buf, hdev, 100, len);
167 "string descriptor with pen parameters not found, assuming not compatible\n");
170 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
172 } else if (rc != len) {
174 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
180 * Fill report descriptor parameters from the string descriptor
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;
193 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
194 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
196 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
197 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
204 * Generate pen report descriptor
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) {
216 * Fill-in the parameters
218 memset(pen, 0, sizeof(*pen));
219 pen->desc_ptr = desc_ptr;
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;
235 * uclogic_params_get_le24() - get a 24-bit little-endian number from a
238 * @p: The pointer to the number buffer.
241 * The retrieved number
243 static s32 uclogic_params_get_le24(const void *p)
246 return b[0] | (b[1] << 8UL) | (b[2] << 16UL);
250 * uclogic_params_pen_init_v2() - initialize tablet interface pen
251 * input and retrieve its parameters from the device, using v2 protocol.
253 * @pen: Pointer to the pen parameters to initialize (to be
254 * cleaned up with uclogic_params_pen_cleanup()). Not modified in
255 * case of error, or if parameters are not found. Cannot be NULL.
256 * @pfound: Location for a flag which is set to true if the parameters
257 * were found, and to false if not (e.g. device was
258 * incompatible). Not modified in case of error. Cannot be NULL.
259 * @hdev: The HID device of the tablet interface to initialize and get
260 * parameters from. Cannot be NULL.
263 * Zero, if successful. A negative errno code on error.
265 static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen,
267 struct hid_device *hdev)
271 /* Buffer for (part of) the string descriptor */
273 /* Descriptor length required */
276 /* Pen report descriptor template parameters */
277 s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
278 __u8 *desc_ptr = NULL;
280 /* Check arguments */
281 if (pen == NULL || pfound == NULL || hdev == NULL) {
287 * Read string descriptor containing pen input parameters.
288 * The specific string descriptor and data were discovered by sniffing
289 * the Windows driver traffic.
290 * NOTE: This enables fully-functional tablet mode.
292 rc = uclogic_params_get_str_desc(&buf, hdev, 200, len);
295 "string descriptor with pen parameters not found, assuming not compatible\n");
298 hid_err(hdev, "failed retrieving pen parameters: %d\n", rc);
300 } else if (rc != len) {
302 "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n",
308 * Check it's not just a catch-all UTF-16LE-encoded ASCII
309 * string (such as the model name) some tablets put into all
310 * unknown string descriptors.
314 (buf[i] >= 0x20 && buf[i] < 0x7f && buf[i + 1] == 0);
318 "string descriptor with pen parameters seems to contain only text, assuming not compatible\n");
324 * Fill report descriptor parameters from the string descriptor
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;
337 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
338 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
340 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
341 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
348 * Generate pen report descriptor
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) {
360 * Fill-in the parameters
362 memset(pen, 0, sizeof(*pen));
363 pen->desc_ptr = desc_ptr;
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;
380 * uclogic_params_frame_cleanup - free resources used by struct
381 * uclogic_params_frame (tablet interface's frame controls input parameters).
382 * Can be called repeatedly.
384 * @frame: Frame controls input parameters to cleanup. Cannot be NULL.
386 static void uclogic_params_frame_cleanup(struct uclogic_params_frame *frame)
388 kfree(frame->desc_ptr);
389 memset(frame, 0, sizeof(*frame));
393 * uclogic_params_frame_init_with_desc() - initialize tablet's frame control
394 * parameters with a static report descriptor.
396 * @frame: Pointer to the frame parameters to initialize (to be cleaned
397 * up with uclogic_params_frame_cleanup()). Not modified in case
398 * of error. Cannot be NULL.
399 * @desc_ptr: Report descriptor pointer. Can be NULL, if desc_size is zero.
400 * @desc_size: Report descriptor size.
401 * @id: Report ID used for frame reports, if they should be tweaked,
405 * Zero, if successful. A negative errno code on error.
407 static int uclogic_params_frame_init_with_desc(
408 struct uclogic_params_frame *frame,
409 const __u8 *desc_ptr,
415 if (frame == NULL || (desc_ptr == NULL && desc_size != 0))
418 copy_desc_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
419 if (copy_desc_ptr == NULL)
422 memset(frame, 0, sizeof(*frame));
423 frame->desc_ptr = copy_desc_ptr;
424 frame->desc_size = desc_size;
430 * uclogic_params_frame_init_v1_buttonpad() - initialize abstract buttonpad
431 * on a v1 tablet interface.
433 * @frame: Pointer to the frame parameters to initialize (to be cleaned
434 * up with uclogic_params_frame_cleanup()). Not modified in case
435 * of error, or if parameters are not found. Cannot be NULL.
436 * @pfound: Location for a flag which is set to true if the parameters
437 * were found, and to false if not (e.g. device was
438 * incompatible). Not modified in case of error. Cannot be NULL.
439 * @hdev: The HID device of the tablet interface to initialize and get
440 * parameters from. Cannot be NULL.
443 * Zero, if successful. A negative errno code on error.
445 static int uclogic_params_frame_init_v1_buttonpad(
446 struct uclogic_params_frame *frame,
448 struct hid_device *hdev)
452 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
453 char *str_buf = NULL;
454 const size_t str_len = 16;
456 /* Check arguments */
457 if (frame == NULL || pfound == NULL || hdev == NULL) {
463 * Enable generic button mode
465 str_buf = kzalloc(str_len, GFP_KERNEL);
466 if (str_buf == NULL) {
471 rc = usb_string(usb_dev, 123, str_buf, str_len);
474 "generic button -enabling string descriptor not found\n");
477 } else if (strncmp(str_buf, "HK On", rc) != 0) {
479 "invalid response to enabling generic buttons: \"%s\"\n",
482 hid_dbg(hdev, "generic buttons enabled\n");
483 rc = uclogic_params_frame_init_with_desc(
485 uclogic_rdesc_buttonpad_v1_arr,
486 uclogic_rdesc_buttonpad_v1_size,
487 UCLOGIC_RDESC_BUTTONPAD_V1_ID);
501 * uclogic_params_cleanup - free resources used by struct uclogic_params
502 * (tablet interface's parameters).
503 * Can be called repeatedly.
505 * @params: Input parameters to cleanup. Cannot be NULL.
507 void uclogic_params_cleanup(struct uclogic_params *params)
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));
519 * Get a replacement report descriptor for a tablet's interface.
521 * @params: The parameters of a tablet interface to get report
522 * descriptor for. Cannot be NULL.
523 * @pdesc: Location for the resulting, kmalloc-allocated report
524 * descriptor pointer, or for NULL, if there's no replacement
525 * report descriptor. Not modified in case of error. Cannot be
527 * @psize: Location for the resulting report descriptor size, not set if
528 * there's no replacement report descriptor. Not modified in case
529 * of error. Cannot be NULL.
532 * Zero, if successful.
533 * -EINVAL, if invalid arguments are supplied.
534 * -ENOMEM, if failed to allocate memory.
536 int uclogic_params_get_desc(const struct uclogic_params *params,
546 /* Check arguments */
547 if (params == NULL || pdesc == NULL || psize == NULL)
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);
557 size += params->desc_size;
559 size += params->pen.desc_size;
561 size += params->frame.desc_size;
563 if (common_present || pen_present || frame_present) {
566 desc = kmalloc(size, GFP_KERNEL);
571 if (common_present) {
572 memcpy(p, params->desc_ptr,
574 p += params->desc_size;
577 memcpy(p, params->pen.desc_ptr,
578 params->pen.desc_size);
579 p += params->pen.desc_size;
582 memcpy(p, params->frame.desc_ptr,
583 params->frame.desc_size);
584 p += params->frame.desc_size;
587 WARN_ON(p != desc + size);
597 * uclogic_params_init_invalid() - initialize tablet interface parameters,
598 * specifying the interface is invalid.
600 * @params: Parameters to initialize (to be cleaned with
601 * uclogic_params_cleanup()). Cannot be NULL.
603 static void uclogic_params_init_invalid(struct uclogic_params *params)
605 params->invalid = true;
609 * uclogic_params_init_with_opt_desc() - initialize tablet interface
610 * parameters with an optional replacement report descriptor. Only modify
611 * report descriptor, if the original report descriptor matches the expected
614 * @params: Parameters to initialize (to be cleaned with
615 * uclogic_params_cleanup()). Not modified in case of
616 * error. Cannot be NULL.
617 * @hdev: The HID device of the tablet interface create the
618 * parameters for. Cannot be NULL.
619 * @orig_desc_size: Expected size of the original report descriptor to
621 * @desc_ptr: Pointer to the replacement report descriptor.
622 * Can be NULL, if desc_size is zero.
623 * @desc_size: Size of the replacement report descriptor.
626 * Zero, if successful. -EINVAL if an invalid argument was passed.
627 * -ENOMEM, if failed to allocate memory.
629 static int uclogic_params_init_with_opt_desc(struct uclogic_params *params,
630 struct hid_device *hdev,
631 unsigned int orig_desc_size,
633 unsigned int desc_size)
635 __u8 *desc_copy_ptr = NULL;
636 unsigned int desc_copy_size;
639 /* Check arguments */
640 if (params == NULL || hdev == NULL ||
641 (desc_ptr == NULL && desc_size != 0)) {
646 /* Replace report descriptor, if it matches */
647 if (hdev->dev_rsize == orig_desc_size) {
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) {
655 desc_copy_size = desc_size;
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;
664 /* Output parameters */
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;
672 kfree(desc_copy_ptr);
677 * uclogic_params_init_with_pen_unused() - initialize tablet interface
678 * parameters preserving original reports and generic HID processing, but
679 * disabling pen usage.
681 * @params: Parameters to initialize (to be cleaned with
682 * uclogic_params_cleanup()). Not modified in case of
683 * error. Cannot be NULL.
685 static void uclogic_params_init_with_pen_unused(struct uclogic_params *params)
687 memset(params, 0, sizeof(*params));
688 params->pen_unused = true;
692 * uclogic_params_init() - initialize a Huion tablet interface and discover
695 * @params: Parameters to fill in (to be cleaned with
696 * uclogic_params_cleanup()). Not modified in case of error.
698 * @hdev: The HID device of the tablet interface to initialize and get
699 * parameters from. Cannot be NULL.
702 * Zero, if successful. A negative errno code on error.
704 static int uclogic_params_huion_init(struct uclogic_params *params,
705 struct hid_device *hdev)
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;
712 /* The resulting parameters (noop) */
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;
718 /* Check arguments */
719 if (params == NULL || hdev == NULL) {
724 /* If it's not a pen interface */
725 if (bInterfaceNumber != 0) {
726 /* TODO: Consider marking the interface invalid */
727 uclogic_params_init_with_pen_unused(&p);
731 /* Try to get firmware version */
732 ver_ptr = kzalloc(ver_len, GFP_KERNEL);
733 if (ver_ptr == NULL) {
737 rc = usb_string(udev, 201, ver_ptr, ver_len);
742 "failed retrieving Huion firmware version: %d\n", rc);
746 /* If this is a transition firmware */
747 if (strcmp(ver_ptr, transition_ver) == 0) {
749 "transition firmware detected, not probing pen v2 parameters\n");
751 /* Try to probe v2 pen parameters */
752 rc = uclogic_params_pen_init_v2(&p.pen, &found, hdev);
755 "failed probing pen v2 parameters: %d\n", rc);
758 hid_dbg(hdev, "pen v2 parameters found\n");
759 /* Create v2 buttonpad parameters */
760 rc = uclogic_params_frame_init_with_desc(
762 uclogic_rdesc_buttonpad_v2_arr,
763 uclogic_rdesc_buttonpad_v2_size,
764 UCLOGIC_RDESC_BUTTONPAD_V2_ID);
767 "failed creating v2 buttonpad parameters: %d\n",
771 /* Set bitmask marking frame reports in pen reports */
772 p.pen_frame_flag = 0x20;
775 hid_dbg(hdev, "pen v2 parameters not found\n");
778 /* Try to probe v1 pen parameters */
779 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
782 "failed probing pen v1 parameters: %d\n", rc);
785 hid_dbg(hdev, "pen v1 parameters found\n");
786 /* Try to probe v1 buttonpad */
787 rc = uclogic_params_frame_init_v1_buttonpad(
791 hid_err(hdev, "v1 buttonpad probing failed: %d\n", rc);
794 hid_dbg(hdev, "buttonpad v1 parameters%s found\n",
795 (found ? "" : " not"));
797 /* Set bitmask marking frame reports */
798 p.pen_frame_flag = 0x20;
802 hid_dbg(hdev, "pen v1 parameters not found\n");
804 uclogic_params_init_invalid(&p);
807 /* Output parameters */
808 memcpy(params, &p, sizeof(*params));
809 memset(&p, 0, sizeof(p));
813 uclogic_params_cleanup(&p);
818 * uclogic_params_init() - initialize a tablet interface and discover its
821 * @params: Parameters to fill in (to be cleaned with
822 * uclogic_params_cleanup()). Not modified in case of error.
824 * @hdev: The HID device of the tablet interface to initialize and get
825 * parameters from. Cannot be NULL. Must be using the USB low-level
826 * driver, i.e. be an actual USB tablet.
829 * Zero, if successful. A negative errno code on error.
831 int uclogic_params_init(struct uclogic_params *params,
832 struct hid_device *hdev)
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;
840 /* The resulting parameters (noop) */
841 struct uclogic_params p = {0, };
843 /* Check arguments */
844 if (params == NULL || hdev == NULL ||
845 !hid_is_using_ll_driver(hdev, &usb_hid_driver)) {
851 * Set replacement report descriptor if the original matches the
852 * specified size. Otherwise keep interface unchanged.
854 #define WITH_OPT_DESC(_orig_desc_token, _new_desc_token) \
855 uclogic_params_init_with_opt_desc( \
857 UCLOGIC_RDESC_##_orig_desc_token##_SIZE, \
858 uclogic_rdesc_##_new_desc_token##_arr, \
859 uclogic_rdesc_##_new_desc_token##_size)
861 #define VID_PID(_vid, _pid) \
862 (((__u32)(_vid) << 16) | ((__u32)(_pid) & U16_MAX))
865 * Handle specific interfaces for specific tablets.
867 * Observe the following logic:
869 * If the interface is recognized as producing certain useful input:
870 * Mark interface as valid.
871 * Output interface parameters.
872 * Else, if the interface is recognized as *not* producing any useful
874 * Mark interface as invalid.
876 * Mark interface as valid.
877 * Output noop parameters.
879 * Rule of thumb: it is better to disable a broken interface than let
880 * it spew garbage input.
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);
890 case VID_PID(USB_VENDOR_ID_UCLOGIC,
891 USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U):
892 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp4030u_fixed);
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 /* Try to probe v1 pen parameters */
901 rc = uclogic_params_pen_init_v1(&p.pen,
905 "pen probing failed: %d\n",
911 "pen parameters not found");
914 uclogic_params_init_invalid(&p);
917 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp5540u_fixed);
922 case VID_PID(USB_VENDOR_ID_UCLOGIC,
923 USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U):
924 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp8060u_fixed);
928 case VID_PID(USB_VENDOR_ID_UCLOGIC,
929 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062):
930 rc = WITH_OPT_DESC(WP1062_ORIG, wp1062_fixed);
934 case VID_PID(USB_VENDOR_ID_UCLOGIC,
935 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850):
936 switch (bInterfaceNumber) {
938 rc = WITH_OPT_DESC(TWHL850_ORIG0, twhl850_fixed0);
943 rc = WITH_OPT_DESC(TWHL850_ORIG1, twhl850_fixed1);
948 rc = WITH_OPT_DESC(TWHL850_ORIG2, twhl850_fixed2);
954 case VID_PID(USB_VENDOR_ID_UCLOGIC,
955 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60):
957 * If it is not a three-interface version, which is known to
958 * respond to initialization.
960 if (bNumInterfaces != 3) {
961 switch (bInterfaceNumber) {
963 rc = WITH_OPT_DESC(TWHA60_ORIG0,
969 rc = WITH_OPT_DESC(TWHA60_ORIG1,
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);
998 case VID_PID(USB_VENDOR_ID_UGTIZER,
999 USB_DEVICE_ID_UGTIZER_TABLET_GP0610):
1000 case VID_PID(USB_VENDOR_ID_UGEE,
1001 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540):
1002 case VID_PID(USB_VENDOR_ID_UGEE,
1003 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640):
1004 case VID_PID(USB_VENDOR_ID_UGEE,
1005 USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720):
1006 /* If this is the pen interface */
1007 if (bInterfaceNumber == 1) {
1008 /* Probe v1 pen parameters */
1009 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1011 hid_err(hdev, "pen probing failed: %d\n", rc);
1015 hid_warn(hdev, "pen parameters not found");
1016 uclogic_params_init_invalid(&p);
1019 /* TODO: Consider marking the interface invalid */
1020 uclogic_params_init_with_pen_unused(&p);
1023 case VID_PID(USB_VENDOR_ID_UGEE,
1024 USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01):
1025 /* If this is the pen and frame interface */
1026 if (bInterfaceNumber == 1) {
1027 /* Probe v1 pen parameters */
1028 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1030 hid_err(hdev, "pen probing failed: %d\n", rc);
1033 /* Initialize frame parameters */
1034 rc = uclogic_params_frame_init_with_desc(
1036 uclogic_rdesc_xppen_deco01_frame_arr,
1037 uclogic_rdesc_xppen_deco01_frame_size,
1042 /* TODO: Consider marking the interface invalid */
1043 uclogic_params_init_with_pen_unused(&p);
1046 case VID_PID(USB_VENDOR_ID_UGEE,
1047 USB_DEVICE_ID_UGEE_TABLET_G5):
1048 /* Ignore non-pen interfaces */
1049 if (bInterfaceNumber != 1) {
1050 uclogic_params_init_invalid(&p);
1054 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1056 hid_err(hdev, "pen probing failed: %d\n", rc);
1059 rc = uclogic_params_frame_init_with_desc(
1061 uclogic_rdesc_ugee_g5_frame_arr,
1062 uclogic_rdesc_ugee_g5_frame_size,
1063 UCLOGIC_RDESC_UGEE_G5_FRAME_ID);
1066 "failed creating buttonpad parameters: %d\n",
1071 UCLOGIC_RDESC_UGEE_G5_FRAME_RE_LSB;
1072 p.frame.dev_id_byte =
1073 UCLOGIC_RDESC_UGEE_G5_FRAME_DEV_ID_BYTE;
1075 hid_warn(hdev, "pen parameters not found");
1076 uclogic_params_init_invalid(&p);
1080 case VID_PID(USB_VENDOR_ID_UGEE,
1081 USB_DEVICE_ID_UGEE_TABLET_EX07S):
1082 /* Ignore non-pen interfaces */
1083 if (bInterfaceNumber != 1) {
1084 uclogic_params_init_invalid(&p);
1088 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1090 hid_err(hdev, "pen probing failed: %d\n", rc);
1093 rc = uclogic_params_frame_init_with_desc(
1095 uclogic_rdesc_ugee_ex07_buttonpad_arr,
1096 uclogic_rdesc_ugee_ex07_buttonpad_size,
1100 "failed creating buttonpad parameters: %d\n",
1105 hid_warn(hdev, "pen parameters not found");
1106 uclogic_params_init_invalid(&p);
1113 #undef WITH_OPT_DESC
1115 /* Output parameters */
1116 memcpy(params, &p, sizeof(*params));
1117 memset(&p, 0, sizeof(p));
1120 uclogic_params_cleanup(&p);