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_pen_v1_template_arr,
211 uclogic_rdesc_pen_v1_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_pen_v1_template_size;
225 pen->id = UCLOGIC_RDESC_PEN_V1_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_pen_v2_template_arr,
355 uclogic_rdesc_pen_v2_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_pen_v2_template_size;
369 pen->id = UCLOGIC_RDESC_PEN_V2_ID;
370 pen->inrange = UCLOGIC_PARAMS_PEN_INRANGE_NONE;
371 pen->fragmented_hires = true;
383 * uclogic_params_frame_cleanup - free resources used by struct
384 * uclogic_params_frame (tablet interface's frame controls input parameters).
385 * Can be called repeatedly.
387 * @frame: Frame controls input parameters to cleanup. Cannot be NULL.
389 static void uclogic_params_frame_cleanup(struct uclogic_params_frame *frame)
391 kfree(frame->desc_ptr);
392 memset(frame, 0, sizeof(*frame));
396 * uclogic_params_frame_init_with_desc() - initialize tablet's frame control
397 * parameters with a static report descriptor.
399 * @frame: Pointer to the frame parameters to initialize (to be cleaned
400 * up with uclogic_params_frame_cleanup()). Not modified in case
401 * of error. Cannot be NULL.
402 * @desc_ptr: Report descriptor pointer. Can be NULL, if desc_size is zero.
403 * @desc_size: Report descriptor size.
404 * @id: Report ID used for frame reports, if they should be tweaked,
408 * Zero, if successful. A negative errno code on error.
410 static int uclogic_params_frame_init_with_desc(
411 struct uclogic_params_frame *frame,
412 const __u8 *desc_ptr,
418 if (frame == NULL || (desc_ptr == NULL && desc_size != 0))
421 copy_desc_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
422 if (copy_desc_ptr == NULL)
425 memset(frame, 0, sizeof(*frame));
426 frame->desc_ptr = copy_desc_ptr;
427 frame->desc_size = desc_size;
433 * uclogic_params_frame_init_v1_buttonpad() - initialize abstract buttonpad
434 * on a v1 tablet interface.
436 * @frame: Pointer to the frame parameters to initialize (to be cleaned
437 * up with uclogic_params_frame_cleanup()). Not modified in case
438 * of error, or if parameters are not found. Cannot be NULL.
439 * @pfound: Location for a flag which is set to true if the parameters
440 * were found, and to false if not (e.g. device was
441 * incompatible). Not modified in case of error. Cannot be NULL.
442 * @hdev: The HID device of the tablet interface to initialize and get
443 * parameters from. Cannot be NULL.
446 * Zero, if successful. A negative errno code on error.
448 static int uclogic_params_frame_init_v1_buttonpad(
449 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_buttonpad_v1_arr,
491 uclogic_rdesc_buttonpad_v1_size,
492 UCLOGIC_RDESC_BUTTONPAD_V1_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) {
515 kfree(params->desc_ptr);
516 if (!params->pen_unused)
517 uclogic_params_pen_cleanup(¶ms->pen);
518 uclogic_params_frame_cleanup(¶ms->frame);
519 memset(params, 0, sizeof(*params));
524 * uclogic_params_get_desc() - Get a replacement report descriptor for a
525 * tablet's interface.
527 * @params: The parameters of a tablet interface to get report
528 * descriptor for. Cannot be NULL.
529 * @pdesc: Location for the resulting, kmalloc-allocated report
530 * descriptor pointer, or for NULL, if there's no replacement
531 * report descriptor. Not modified in case of error. Cannot be
533 * @psize: Location for the resulting report descriptor size, not set if
534 * there's no replacement report descriptor. Not modified in case
535 * of error. Cannot be NULL.
538 * Zero, if successful.
539 * -EINVAL, if invalid arguments are supplied.
540 * -ENOMEM, if failed to allocate memory.
542 int uclogic_params_get_desc(const struct uclogic_params *params,
552 /* Check arguments */
553 if (params == NULL || pdesc == NULL || psize == NULL)
558 common_present = (params->desc_ptr != NULL);
559 pen_present = (!params->pen_unused && params->pen.desc_ptr != NULL);
560 frame_present = (params->frame.desc_ptr != NULL);
563 size += params->desc_size;
565 size += params->pen.desc_size;
567 size += params->frame.desc_size;
569 if (common_present || pen_present || frame_present) {
572 desc = kmalloc(size, GFP_KERNEL);
577 if (common_present) {
578 memcpy(p, params->desc_ptr,
580 p += params->desc_size;
583 memcpy(p, params->pen.desc_ptr,
584 params->pen.desc_size);
585 p += params->pen.desc_size;
588 memcpy(p, params->frame.desc_ptr,
589 params->frame.desc_size);
590 p += params->frame.desc_size;
593 WARN_ON(p != desc + size);
603 * uclogic_params_init_invalid() - initialize tablet interface parameters,
604 * specifying the interface is invalid.
606 * @params: Parameters to initialize (to be cleaned with
607 * uclogic_params_cleanup()). Cannot be NULL.
609 static void uclogic_params_init_invalid(struct uclogic_params *params)
611 params->invalid = true;
615 * uclogic_params_init_with_opt_desc() - initialize tablet interface
616 * parameters with an optional replacement report descriptor. Only modify
617 * report descriptor, if the original report descriptor matches the expected
620 * @params: Parameters to initialize (to be cleaned with
621 * uclogic_params_cleanup()). Not modified in case of
622 * error. Cannot be NULL.
623 * @hdev: The HID device of the tablet interface create the
624 * parameters for. Cannot be NULL.
625 * @orig_desc_size: Expected size of the original report descriptor to
627 * @desc_ptr: Pointer to the replacement report descriptor.
628 * Can be NULL, if desc_size is zero.
629 * @desc_size: Size of the replacement report descriptor.
632 * Zero, if successful. -EINVAL if an invalid argument was passed.
633 * -ENOMEM, if failed to allocate memory.
635 static int uclogic_params_init_with_opt_desc(struct uclogic_params *params,
636 struct hid_device *hdev,
637 unsigned int orig_desc_size,
639 unsigned int desc_size)
641 __u8 *desc_copy_ptr = NULL;
642 unsigned int desc_copy_size;
645 /* Check arguments */
646 if (params == NULL || hdev == NULL ||
647 (desc_ptr == NULL && desc_size != 0)) {
652 /* Replace report descriptor, if it matches */
653 if (hdev->dev_rsize == orig_desc_size) {
655 "device report descriptor matches the expected size, replacing\n");
656 desc_copy_ptr = kmemdup(desc_ptr, desc_size, GFP_KERNEL);
657 if (desc_copy_ptr == NULL) {
661 desc_copy_size = desc_size;
664 "device report descriptor doesn't match the expected size (%u != %u), preserving\n",
665 hdev->dev_rsize, orig_desc_size);
666 desc_copy_ptr = NULL;
670 /* Output parameters */
671 memset(params, 0, sizeof(*params));
672 params->desc_ptr = desc_copy_ptr;
673 desc_copy_ptr = NULL;
674 params->desc_size = desc_copy_size;
678 kfree(desc_copy_ptr);
683 * uclogic_params_init_with_pen_unused() - initialize tablet interface
684 * parameters preserving original reports and generic HID processing, but
685 * disabling pen usage.
687 * @params: Parameters to initialize (to be cleaned with
688 * uclogic_params_cleanup()). Not modified in case of
689 * error. Cannot be NULL.
691 static void uclogic_params_init_with_pen_unused(struct uclogic_params *params)
693 memset(params, 0, sizeof(*params));
694 params->pen_unused = true;
698 * uclogic_params_huion_init() - initialize a Huion tablet interface and discover
701 * @params: Parameters to fill in (to be cleaned with
702 * uclogic_params_cleanup()). Not modified in case of error.
704 * @hdev: The HID device of the tablet interface to initialize and get
705 * parameters from. Cannot be NULL.
708 * Zero, if successful. A negative errno code on error.
710 static int uclogic_params_huion_init(struct uclogic_params *params,
711 struct hid_device *hdev)
714 struct usb_device *udev;
715 struct usb_interface *iface;
716 __u8 bInterfaceNumber;
718 /* The resulting parameters (noop) */
719 struct uclogic_params p = {0, };
720 static const char transition_ver[] = "HUION_T153_160607";
721 char *ver_ptr = NULL;
722 const size_t ver_len = sizeof(transition_ver) + 1;
724 /* Check arguments */
725 if (params == NULL || hdev == NULL) {
730 udev = hid_to_usb_dev(hdev);
731 iface = to_usb_interface(hdev->dev.parent);
732 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
734 /* If it's not a pen interface */
735 if (bInterfaceNumber != 0) {
736 /* TODO: Consider marking the interface invalid */
737 uclogic_params_init_with_pen_unused(&p);
741 /* Try to get firmware version */
742 ver_ptr = kzalloc(ver_len, GFP_KERNEL);
743 if (ver_ptr == NULL) {
747 rc = usb_string(udev, 201, ver_ptr, ver_len);
752 "failed retrieving Huion firmware version: %d\n", rc);
756 /* If this is a transition firmware */
757 if (strcmp(ver_ptr, transition_ver) == 0) {
759 "transition firmware detected, not probing pen v2 parameters\n");
761 /* Try to probe v2 pen parameters */
762 rc = uclogic_params_pen_init_v2(&p.pen, &found, hdev);
765 "failed probing pen v2 parameters: %d\n", rc);
768 hid_dbg(hdev, "pen v2 parameters found\n");
769 /* Create v2 buttonpad parameters */
770 rc = uclogic_params_frame_init_with_desc(
772 uclogic_rdesc_buttonpad_v2_arr,
773 uclogic_rdesc_buttonpad_v2_size,
774 UCLOGIC_RDESC_BUTTONPAD_V2_ID);
777 "failed creating v2 buttonpad parameters: %d\n",
781 /* Set bitmask marking frame reports in pen reports */
782 p.pen_frame_flag = 0x20;
785 hid_dbg(hdev, "pen v2 parameters not found\n");
788 /* Try to probe v1 pen parameters */
789 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
792 "failed probing pen v1 parameters: %d\n", rc);
795 hid_dbg(hdev, "pen v1 parameters found\n");
796 /* Try to probe v1 buttonpad */
797 rc = uclogic_params_frame_init_v1_buttonpad(
801 hid_err(hdev, "v1 buttonpad probing failed: %d\n", rc);
804 hid_dbg(hdev, "buttonpad v1 parameters%s found\n",
805 (found ? "" : " not"));
807 /* Set bitmask marking frame reports */
808 p.pen_frame_flag = 0x20;
812 hid_dbg(hdev, "pen v1 parameters not found\n");
814 uclogic_params_init_invalid(&p);
817 /* Output parameters */
818 memcpy(params, &p, sizeof(*params));
819 memset(&p, 0, sizeof(p));
823 uclogic_params_cleanup(&p);
828 * uclogic_params_init() - initialize a tablet interface and discover its
831 * @params: Parameters to fill in (to be cleaned with
832 * uclogic_params_cleanup()). Not modified in case of error.
834 * @hdev: The HID device of the tablet interface to initialize and get
835 * parameters from. Cannot be NULL. Must be using the USB low-level
836 * driver, i.e. be an actual USB tablet.
839 * Zero, if successful. A negative errno code on error.
841 int uclogic_params_init(struct uclogic_params *params,
842 struct hid_device *hdev)
845 struct usb_device *udev;
847 struct usb_interface *iface;
848 __u8 bInterfaceNumber;
850 /* The resulting parameters (noop) */
851 struct uclogic_params p = {0, };
853 /* Check arguments */
854 if (params == NULL || hdev == NULL || !hid_is_usb(hdev)) {
859 udev = hid_to_usb_dev(hdev);
860 bNumInterfaces = udev->config->desc.bNumInterfaces;
861 iface = to_usb_interface(hdev->dev.parent);
862 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
865 * Set replacement report descriptor if the original matches the
866 * specified size. Otherwise keep interface unchanged.
868 #define WITH_OPT_DESC(_orig_desc_token, _new_desc_token) \
869 uclogic_params_init_with_opt_desc( \
871 UCLOGIC_RDESC_##_orig_desc_token##_SIZE, \
872 uclogic_rdesc_##_new_desc_token##_arr, \
873 uclogic_rdesc_##_new_desc_token##_size)
875 #define VID_PID(_vid, _pid) \
876 (((__u32)(_vid) << 16) | ((__u32)(_pid) & U16_MAX))
879 * Handle specific interfaces for specific tablets.
881 * Observe the following logic:
883 * If the interface is recognized as producing certain useful input:
884 * Mark interface as valid.
885 * Output interface parameters.
886 * Else, if the interface is recognized as *not* producing any useful
888 * Mark interface as invalid.
890 * Mark interface as valid.
891 * Output noop parameters.
893 * Rule of thumb: it is better to disable a broken interface than let
894 * it spew garbage input.
897 switch (VID_PID(hdev->vendor, hdev->product)) {
898 case VID_PID(USB_VENDOR_ID_UCLOGIC,
899 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209):
900 rc = WITH_OPT_DESC(PF1209_ORIG, pf1209_fixed);
904 case VID_PID(USB_VENDOR_ID_UCLOGIC,
905 USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U):
906 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp4030u_fixed);
910 case VID_PID(USB_VENDOR_ID_UCLOGIC,
911 USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U):
912 if (hdev->dev_rsize == UCLOGIC_RDESC_WP5540U_V2_ORIG_SIZE) {
913 if (bInterfaceNumber == 0) {
914 /* Try to probe v1 pen parameters */
915 rc = uclogic_params_pen_init_v1(&p.pen,
919 "pen probing failed: %d\n",
925 "pen parameters not found");
928 uclogic_params_init_invalid(&p);
931 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp5540u_fixed);
936 case VID_PID(USB_VENDOR_ID_UCLOGIC,
937 USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U):
938 rc = WITH_OPT_DESC(WPXXXXU_ORIG, wp8060u_fixed);
942 case VID_PID(USB_VENDOR_ID_UCLOGIC,
943 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062):
944 rc = WITH_OPT_DESC(WP1062_ORIG, wp1062_fixed);
948 case VID_PID(USB_VENDOR_ID_UCLOGIC,
949 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850):
950 switch (bInterfaceNumber) {
952 rc = WITH_OPT_DESC(TWHL850_ORIG0, twhl850_fixed0);
957 rc = WITH_OPT_DESC(TWHL850_ORIG1, twhl850_fixed1);
962 rc = WITH_OPT_DESC(TWHL850_ORIG2, twhl850_fixed2);
968 case VID_PID(USB_VENDOR_ID_UCLOGIC,
969 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60):
971 * If it is not a three-interface version, which is known to
972 * respond to initialization.
974 if (bNumInterfaces != 3) {
975 switch (bInterfaceNumber) {
977 rc = WITH_OPT_DESC(TWHA60_ORIG0,
983 rc = WITH_OPT_DESC(TWHA60_ORIG1,
992 case VID_PID(USB_VENDOR_ID_HUION,
993 USB_DEVICE_ID_HUION_TABLET):
994 case VID_PID(USB_VENDOR_ID_HUION,
995 USB_DEVICE_ID_HUION_HS64):
996 case VID_PID(USB_VENDOR_ID_UCLOGIC,
997 USB_DEVICE_ID_HUION_TABLET):
998 case VID_PID(USB_VENDOR_ID_UCLOGIC,
999 USB_DEVICE_ID_YIYNOVA_TABLET):
1000 case VID_PID(USB_VENDOR_ID_UCLOGIC,
1001 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_81):
1002 case VID_PID(USB_VENDOR_ID_UCLOGIC,
1003 USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3):
1004 case VID_PID(USB_VENDOR_ID_UCLOGIC,
1005 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_45):
1006 case VID_PID(USB_VENDOR_ID_UCLOGIC,
1007 USB_DEVICE_ID_UCLOGIC_UGEE_TABLET_47):
1008 rc = uclogic_params_huion_init(&p, hdev);
1012 case VID_PID(USB_VENDOR_ID_UGTIZER,
1013 USB_DEVICE_ID_UGTIZER_TABLET_GP0610):
1014 case VID_PID(USB_VENDOR_ID_UGTIZER,
1015 USB_DEVICE_ID_UGTIZER_TABLET_GT5040):
1016 case VID_PID(USB_VENDOR_ID_UGEE,
1017 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540):
1018 case VID_PID(USB_VENDOR_ID_UGEE,
1019 USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640):
1020 case VID_PID(USB_VENDOR_ID_UGEE,
1021 USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720):
1022 /* If this is the pen 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);
1031 hid_warn(hdev, "pen parameters not found");
1032 uclogic_params_init_invalid(&p);
1035 /* TODO: Consider marking the interface invalid */
1036 uclogic_params_init_with_pen_unused(&p);
1039 case VID_PID(USB_VENDOR_ID_UGEE,
1040 USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01):
1041 /* If this is the pen and frame interface */
1042 if (bInterfaceNumber == 1) {
1043 /* Probe v1 pen parameters */
1044 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1046 hid_err(hdev, "pen probing failed: %d\n", rc);
1049 /* Initialize frame parameters */
1050 rc = uclogic_params_frame_init_with_desc(
1052 uclogic_rdesc_xppen_deco01_frame_arr,
1053 uclogic_rdesc_xppen_deco01_frame_size,
1058 /* TODO: Consider marking the interface invalid */
1059 uclogic_params_init_with_pen_unused(&p);
1062 case VID_PID(USB_VENDOR_ID_TRUST,
1063 USB_DEVICE_ID_TRUST_PANORA_TABLET):
1064 case VID_PID(USB_VENDOR_ID_UGEE,
1065 USB_DEVICE_ID_UGEE_TABLET_G5):
1066 /* Ignore non-pen interfaces */
1067 if (bInterfaceNumber != 1) {
1068 uclogic_params_init_invalid(&p);
1072 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1074 hid_err(hdev, "pen probing failed: %d\n", rc);
1077 rc = uclogic_params_frame_init_with_desc(
1079 uclogic_rdesc_ugee_g5_frame_arr,
1080 uclogic_rdesc_ugee_g5_frame_size,
1081 UCLOGIC_RDESC_UGEE_G5_FRAME_ID);
1084 "failed creating buttonpad parameters: %d\n",
1089 UCLOGIC_RDESC_UGEE_G5_FRAME_RE_LSB;
1090 p.frame.dev_id_byte =
1091 UCLOGIC_RDESC_UGEE_G5_FRAME_DEV_ID_BYTE;
1093 hid_warn(hdev, "pen parameters not found");
1094 uclogic_params_init_invalid(&p);
1098 case VID_PID(USB_VENDOR_ID_UGEE,
1099 USB_DEVICE_ID_UGEE_TABLET_EX07S):
1100 /* Ignore non-pen interfaces */
1101 if (bInterfaceNumber != 1) {
1102 uclogic_params_init_invalid(&p);
1106 rc = uclogic_params_pen_init_v1(&p.pen, &found, hdev);
1108 hid_err(hdev, "pen probing failed: %d\n", rc);
1111 rc = uclogic_params_frame_init_with_desc(
1113 uclogic_rdesc_ugee_ex07_buttonpad_arr,
1114 uclogic_rdesc_ugee_ex07_buttonpad_size,
1118 "failed creating buttonpad parameters: %d\n",
1123 hid_warn(hdev, "pen parameters not found");
1124 uclogic_params_init_invalid(&p);
1131 #undef WITH_OPT_DESC
1133 /* Output parameters */
1134 memcpy(params, &p, sizeof(*params));
1135 memset(&p, 0, sizeof(p));
1138 uclogic_params_cleanup(&p);