From patchwork Sat Jun 11 11:39:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 581481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D29BCCA47A for ; Sat, 11 Jun 2022 11:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232862AbiFKLjY (ORCPT ); Sat, 11 Jun 2022 07:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbiFKLjX (ORCPT ); Sat, 11 Jun 2022 07:39:23 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE37DFF0; Sat, 11 Jun 2022 04:39:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u8so1568314wrm.13; Sat, 11 Jun 2022 04:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3PjQuKMkTY1kyPsdXkRWcy11RqWiSJraBoDtsiZIFcs=; b=pMAV4YZDWCCWc6eMKct6qOVKz92iXyCAAj6bSWuv4NVXkN0+IWOEQR8ZeWUHIQmJHS mjZAKDrY44b8qeA0wJvGleRTdaUHPSx78Oeno5tSF6rVODsXtE30gfRE6HMPN9qMw5Oc cD1Z5XkYo8Ftc+6J/KafWm/L8U4chJ+2mwRFKwHhqhqDnzmYDtwiQ7s0gV+LT2rzC4TE 7l4G5QQoZEgoA2RZjHUs605L9aYxlOMy3yUNX19cImlBP+BxIXeOieQt0/romLmim5Hm r4T5+CH30zPpwt8gIX7mCEeL0OoP22JlMIBLjhq895y57HOdz0U8tad4h03tUkb6Hiox rD/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3PjQuKMkTY1kyPsdXkRWcy11RqWiSJraBoDtsiZIFcs=; b=GfLdbh/Z+yyvRVyme8yHETiXvy+TpL32R3AAJcXoIwAK6Uw41Jj973QaUz0vqyN4gT 6r49s7UpLALJzY1a27/lMEvAhYzFZfRblYf5UrHRHzDpfrQBYZtsAoTCcGB9xWiEXtE0 BXI17bgzLUVBXnI2GATwQZRFlf8WeFj0EytzK8hBOJKAebo1w6IcrwRiJRe0qdZNMnuA +2NWiT64LPqp0X1TQKSAm2u/yJv/zbzhEFCjRrcTA4EqhRxZd5Pcmsl8Gbt89QtZpShV efSTmZAVXOJZNonBXExRJreDEsFJf3ooGZEsi4HRGRbQfP186RPMls9vn0dUFnQdlxlJ ytgA== X-Gm-Message-State: AOAM530hB77Nhd4FTJumOnpe+MTYDqNKVt2vYQNbHj9Utmap8LdEBgcB 3wlV0CzH4PhHSbzaLgu2UU27PAZrJw4= X-Google-Smtp-Source: ABdhPJzc8Pvxr69wjXMxllNgQSpnO+W1ifZeTXJfLLTeqTD7bbuEmGlT069kZ9+kpx5w61LrtA1qgQ== X-Received: by 2002:a5d:624e:0:b0:210:a42:f29d with SMTP id m14-20020a5d624e000000b002100a42f29dmr47648017wrv.615.1654947560749; Sat, 11 Jun 2022 04:39:20 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id g15-20020a05600c4ecf00b0039c4945c753sm6574198wmq.39.2022.06.11.04.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 04:39:20 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stefanberzl@gmail.com, dlatypov@google.com, kunit-dev@googlegroups.com, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v4 1/4] HID: uclogic: Make template placeholder IDs generic Date: Sat, 11 Jun 2022 13:39:11 +0200 Message-Id: <20220611113914.355577-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611113914.355577-1-jose.exposito89@gmail.com> References: <20220611113914.355577-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Up until now, the report descriptor template parameter IDs were only used with pen report descriptors and they were named accordingly. Rename the enum and the total number of IDs to make them interface agnostic. Refactor, no functional changes. Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params.c | 4 ++-- drivers/hid/hid-uclogic-rdesc.c | 14 +++++++------- drivers/hid/hid-uclogic-rdesc.h | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index db838f16282d..b43142f98a8b 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -234,7 +234,7 @@ static int uclogic_params_pen_init_v1(struct uclogic_params_pen *pen, const int len = 12; s32 resolution; /* Pen report descriptor template parameters */ - s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM]; + s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; __u8 *desc_ptr = NULL; /* Check arguments */ @@ -379,7 +379,7 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, size_t i; s32 resolution; /* Pen report descriptor template parameters */ - s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM]; + s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; __u8 *desc_ptr = NULL; /* Check arguments */ diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 13f9ce73f1b1..7126fba80968 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -979,7 +979,7 @@ const size_t uclogic_rdesc_xppen_deco01_frame_size = * uclogic_rdesc_template_apply() - apply report descriptor parameters to a * report descriptor template, creating a report descriptor. Copies the * template over to the new report descriptor and replaces every occurrence of - * UCLOGIC_RDESC_PH_HEAD, followed by an index byte, with the value from the + * UCLOGIC_RDESC_PEN_PH_HEAD, followed by an index byte, with the value from the * parameter list at that index. * * @template_ptr: Pointer to the template buffer. @@ -996,7 +996,7 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, const s32 *param_list, size_t param_num) { - static const __u8 head[] = {UCLOGIC_RDESC_PH_HEAD}; + static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD}; __u8 *rdesc_ptr; __u8 *p; s32 v; @@ -1005,12 +1005,12 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, if (rdesc_ptr == NULL) return NULL; - for (p = rdesc_ptr; p + sizeof(head) < rdesc_ptr + template_size;) { - if (memcmp(p, head, sizeof(head)) == 0 && - p[sizeof(head)] < param_num) { - v = param_list[p[sizeof(head)]]; + for (p = rdesc_ptr; p + sizeof(pen_head) < rdesc_ptr + template_size;) { + if (memcmp(p, pen_head, sizeof(pen_head)) == 0 && + p[sizeof(pen_head)] < param_num) { + v = param_list[p[sizeof(pen_head)]]; put_unaligned(cpu_to_le32(v), (s32 *)p); - p += sizeof(head) + 1; + p += sizeof(pen_head) + 1; } else { p++; } diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index 0c6e95e8bde7..9d37090c39d1 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -81,7 +81,7 @@ extern __u8 uclogic_rdesc_twha60_fixed1_arr[]; extern const size_t uclogic_rdesc_twha60_fixed1_size; /* Report descriptor template placeholder head */ -#define UCLOGIC_RDESC_PH_HEAD 0xFE, 0xED, 0x1D +#define UCLOGIC_RDESC_PEN_PH_HEAD 0xFE, 0xED, 0x1D /* Apply report descriptor parameters to a report descriptor template */ extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, @@ -89,19 +89,19 @@ extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, const s32 *param_list, size_t param_num); -/* Pen report descriptor template placeholder IDs */ -enum uclogic_rdesc_pen_ph_id { +/* Report descriptor template placeholder IDs */ +enum uclogic_rdesc_ph_id { UCLOGIC_RDESC_PEN_PH_ID_X_LM, UCLOGIC_RDESC_PEN_PH_ID_X_PM, UCLOGIC_RDESC_PEN_PH_ID_Y_LM, UCLOGIC_RDESC_PEN_PH_ID_Y_PM, UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM, - UCLOGIC_RDESC_PEN_PH_ID_NUM + UCLOGIC_RDESC_PH_ID_NUM }; /* Report descriptor pen template placeholder */ #define UCLOGIC_RDESC_PEN_PH(_ID) \ - UCLOGIC_RDESC_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID + UCLOGIC_RDESC_PEN_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID /* Report ID for v1 pen reports */ #define UCLOGIC_RDESC_V1_PEN_ID 0x07 From patchwork Sat Jun 11 11:39:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 581212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE5F7C433EF for ; Sat, 11 Jun 2022 11:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233024AbiFKLjZ (ORCPT ); Sat, 11 Jun 2022 07:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbiFKLjZ (ORCPT ); Sat, 11 Jun 2022 07:39:25 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD7816540; Sat, 11 Jun 2022 04:39:23 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id o8so1616601wro.3; Sat, 11 Jun 2022 04:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p9el9auPnq6m6H+z0qpqCnwqiGaqlZa/48GpKoNNR/g=; b=iWicCkBMa5ubbvSCKu1d9G7/O9QYfHJxBaudj/9sZnJN9pOeDqlUrXzKL6fLCikzm9 /866KjSAmJNuvvEodN+Nftz17BMeJzU8qF5QGpKSoWAS8lnF1aH/wWXJjQe/auC8sZAz xdzvYDapUzcyWXWB1VAMlETGL1E9KbgCwkQrZ8YY4TH4ntz06J7Sg2G7PtWLJlsiTzVN zMPvbDktGbyYotsMlvgsHZE/Xu4AAhSO4zGQ9nxRif0mqFFL8Sv82b5KvK1V9y1a+sxr 3BFOhI4WD4xt7SBr03bep1NC9ttZr/sS0MrsLaDIpVsQlfc41G/4wfFVKHJwaq3ayWKE bRwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p9el9auPnq6m6H+z0qpqCnwqiGaqlZa/48GpKoNNR/g=; b=trYmj2zkqi7fkNc9vwT/7Wd9953E7KtKye12NPNSU3nvJtPmhxajDORA6uHeU/Rzar dJo3bje46ap7GmJy8uZZ2x1tXf/JUkEMVBFOJ/5yhQoAyGllXfUYL+ulrOAt6HqNUSLF hqHFeABzN8m/55c4XQZvxkf+BeicOFthUjBRkTS+G7HiDDaawwpyI8PpIhkOydGcyGwn steCQG1mg5bf/9yYbABLRGPiosU2Krg7a6SGuq6EhBD0kbESZUSGRcEKRySZalTk/d3m 9akAvVrkZhtg3mMxPwwMGNDDyaCgcMbBt2cRsYV3hxGJpioGADTsMa2EQlCgr47mEVeW fudA== X-Gm-Message-State: AOAM532t3oj4u88naFinXxlRp77d6oA+EcJ9rHyFTTqo6ogbSZqs3AhH Zw8NkCVjVsm2MJKqOV27s8Zpq8O1aXA= X-Google-Smtp-Source: ABdhPJwdmsGGVtNQ7Ntk/KrGGQQFxxRfqWdhnADjZeAHAKx9zeCrkXLJE2cbiZ1s03NGdzxjiF4rCw== X-Received: by 2002:a05:6000:1869:b0:211:7f25:89da with SMTP id d9-20020a056000186900b002117f2589damr48444955wri.696.1654947562243; Sat, 11 Jun 2022 04:39:22 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id g15-20020a05600c4ecf00b0039c4945c753sm6574198wmq.39.2022.06.11.04.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 04:39:21 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stefanberzl@gmail.com, dlatypov@google.com, kunit-dev@googlegroups.com, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v4 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply() Date: Sat, 11 Jun 2022 13:39:12 +0200 Message-Id: <20220611113914.355577-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611113914.355577-1-jose.exposito89@gmail.com> References: <20220611113914.355577-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The uclogic_rdesc_template_apply() function is used by the driver to generate HID descriptors from templates. In order to avoid regressions in future patches, add KUnit tests to test the function. To run the tests: $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/hid \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Signed-off-by: José Expósito --- drivers/hid/.kunitconfig | 5 + drivers/hid/Kconfig | 16 +++ drivers/hid/Makefile | 3 + drivers/hid/hid-uclogic-rdesc-test.c | 183 +++++++++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 drivers/hid/.kunitconfig create mode 100644 drivers/hid/hid-uclogic-rdesc-test.c diff --git a/drivers/hid/.kunitconfig b/drivers/hid/.kunitconfig new file mode 100644 index 000000000000..04daeff5c970 --- /dev/null +++ b/drivers/hid/.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_USB=y +CONFIG_USB_HID=y +CONFIG_HID_UCLOGIC=y +CONFIG_HID_KUNIT_TEST=y diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 70da5931082f..6ce92830b5d1 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1306,6 +1306,22 @@ config HID_MCP2221 To compile this driver as a module, choose M here: the module will be called hid-mcp2221.ko. +config HID_KUNIT_TEST + bool "KUnit tests for HID" if !KUNIT_ALL_TESTS + depends on KUNIT=y + depends on HID_UCLOGIC + default KUNIT_ALL_TESTS + help + This builds unit tests for HID. This option is not useful for + distributions or general kernels, but only for kernel + developers working on HID and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + endmenu endif # HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index cac2cbe26d11..b0bef8098139 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -144,6 +144,9 @@ obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o obj-$(CONFIG_HID_SENSOR_CUSTOM_SENSOR) += hid-sensor-custom.o +obj-$(CONFIG_HID_KUNIT_TEST) += hid-uclogic-rdesc.o \ + hid-uclogic-rdesc-test.o + obj-$(CONFIG_USB_HID) += usbhid/ obj-$(CONFIG_USB_MOUSE) += usbhid/ obj-$(CONFIG_USB_KBD) += usbhid/ diff --git a/drivers/hid/hid-uclogic-rdesc-test.c b/drivers/hid/hid-uclogic-rdesc-test.c new file mode 100644 index 000000000000..ded59e226230 --- /dev/null +++ b/drivers/hid/hid-uclogic-rdesc-test.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/* + * HID driver for UC-Logic devices not fully compliant with HID standard + * + * Copyright (c) 2022 José Expósito + */ + +#include +#include "./hid-uclogic-rdesc.h" + +struct uclogic_template_case { + const char *name; + const __u8 *template; + size_t template_size; + const s32 *param_list; + size_t param_num; + const __u8 *expected; +}; + +static const s32 params_pen_all[UCLOGIC_RDESC_PH_ID_NUM] = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB, + [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0xCC, + [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0xDD, + [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0xEE, +}; + +static const s32 params_pen_some[] = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB, +}; + +static const __u8 template_empty[] = { }; +static const __u8 template_small[] = { 0x00 }; +static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D }; + +static const __u8 template_pen_ph_end[] = { + 0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD +}; + +static const __u8 template_pen_all_params[] = { + UCLOGIC_RDESC_PEN_PH(X_LM), + 0x47, UCLOGIC_RDESC_PEN_PH(X_PM), + 0x27, UCLOGIC_RDESC_PEN_PH(Y_LM), + UCLOGIC_RDESC_PEN_PH(Y_PM), + 0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM), +}; + +static const __u8 expected_pen_all_params[] = { + 0xAA, 0x00, 0x00, 0x00, + 0x47, 0xBB, 0x00, 0x00, 0x00, + 0x27, 0xCC, 0x00, 0x00, 0x00, + 0xDD, 0x00, 0x00, 0x00, + 0x00, 0xEE, 0x00, 0x00, 0x00, +}; + +static const __u8 template_pen_some_params[] = { + 0x01, 0x02, + UCLOGIC_RDESC_PEN_PH(X_LM), + 0x03, UCLOGIC_RDESC_PEN_PH(X_PM), + 0x04, 0x05, +}; + +static const __u8 expected_pen_some_params[] = { + 0x01, 0x02, + 0xAA, 0x00, 0x00, 0x00, + 0x03, 0xBB, 0x00, 0x00, 0x00, + 0x04, 0x05, +}; + +static const __u8 template_params_none[] = { + 0x27, UCLOGIC_RDESC_PEN_PH(Y_LM), + UCLOGIC_RDESC_PEN_PH(Y_PM), + 0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM), +}; + +static struct uclogic_template_case uclogic_template_cases[] = { + { + .name = "Empty template", + .template = template_empty, + .template_size = sizeof(template_empty), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = template_empty, + }, + { + .name = "Template smaller than the placeholder", + .template = template_small, + .template_size = sizeof(template_small), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = template_small, + }, + { + .name = "No placeholder", + .template = template_no_ph, + .template_size = sizeof(template_no_ph), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = template_no_ph, + }, + { + .name = "Pen placeholder at the end, without ID", + .template = template_pen_ph_end, + .template_size = sizeof(template_pen_ph_end), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = template_pen_ph_end, + }, + { + .name = "All params present in the pen template", + .template = template_pen_all_params, + .template_size = sizeof(template_pen_all_params), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = expected_pen_all_params, + }, + { + .name = "Some params present in the pen template (complete param list)", + .template = template_pen_some_params, + .template_size = sizeof(template_pen_some_params), + .param_list = params_pen_all, + .param_num = ARRAY_SIZE(params_pen_all), + .expected = expected_pen_some_params, + }, + { + .name = "Some params present in the pen template (incomplete param list)", + .template = template_pen_some_params, + .template_size = sizeof(template_pen_some_params), + .param_list = params_pen_some, + .param_num = ARRAY_SIZE(params_pen_some), + .expected = expected_pen_some_params, + }, + { + .name = "No params present in the template", + .template = template_params_none, + .template_size = sizeof(template_params_none), + .param_list = params_pen_some, + .param_num = ARRAY_SIZE(params_pen_some), + .expected = template_params_none, + }, +}; + +static void uclogic_template_case_desc(struct uclogic_template_case *t, + char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(uclogic_template, uclogic_template_cases, + uclogic_template_case_desc); + +static void uclogic_template_test(struct kunit *test) +{ + __u8 *res; + const struct uclogic_template_case *params = test->param_value; + + res = uclogic_rdesc_template_apply(params->template, + params->template_size, + params->param_list, + params->param_num); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res); + KUNIT_EXPECT_EQ(test, 0, + memcmp(res, params->expected, params->template_size)); + kfree(res); +} + +static struct kunit_case hid_uclogic_rdesc_test_cases[] = { + KUNIT_CASE_PARAM(uclogic_template_test, uclogic_template_gen_params), + {} +}; + +static struct kunit_suite hid_uclogic_rdesc_test_suite = { + .name = "hid-uclogic-rdesc-test", + .test_cases = hid_uclogic_rdesc_test_cases, +}; + +kunit_test_suite(hid_uclogic_rdesc_test_suite); + +MODULE_DESCRIPTION("KUnit tests for the UC-Logic driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("José Expósito "); From patchwork Sat Jun 11 11:39:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 581480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2415C43334 for ; Sat, 11 Jun 2022 11:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233105AbiFKLjb (ORCPT ); Sat, 11 Jun 2022 07:39:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbiFKLj0 (ORCPT ); Sat, 11 Jun 2022 07:39:26 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 122DFDFF0; Sat, 11 Jun 2022 04:39:25 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id x17so1601740wrg.6; Sat, 11 Jun 2022 04:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aAr8shjvKRcCfv7HNBBK8SL5xstDJCBPnCo1qU9xjjY=; b=bfZz8x2DPAMl5wzFr0eqjMOR3rp/PnF/1kHrJ1GV5cQID+wrB4zo5q9Az4FxfOvfCT rXXyaKW0rAHNd0NtShSX5djrqAv4cqNVWF/QomLV2iqqEyRj2tlZEWFF9xJNVH4OGOnZ bCqRm3gNGTRdaVwjv0WSTGTGH1NUub6SDOW1udifGJ36jAQA/kUMGLINw8dU4hT7V7BF C+mfIoJ8x2JKnCt7joXwPbuk7Zct82o5m0CQ/cDzoLpWHpW2FWRHTOkwl6FzuxzZEYv3 wD7OMHWRAPf8NP1Il0uG3ZA4YHRc2TIxKHD3vDTuvE/i2ia37ykymX+r7AM16sOcqcbh ot4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aAr8shjvKRcCfv7HNBBK8SL5xstDJCBPnCo1qU9xjjY=; b=FzV1emoXOdXZ2S3HidSumvcU1UloLB1M+ITePNxa9TY8gIJpFk6axjrn0q0vUg+euO SeiLb7n4n7AIhorlENdeQxNsk3NPjDYxl7kERGWk8d+a3XVQoR1AdwDTr/E08flHW6+U V1DZUwc19huENq0z0pIiWjkeqoZn+vXxSjL/3gbEkPy0x9eMKTZHiS+Et3KwbAb5UcPg llQOZRURT2pty4/jWbOhwhqjIapu5Q4oxLzmfYz5HbrQR8hfj397sJNoQJXLKQLBu1jk uy4lift3yPfoAUxN2CZBRdhWQebGF+ldgCbzMqKlB16H4vo4vywF04AYzBFvfYVroJNz 2REg== X-Gm-Message-State: AOAM531HhrsZ5yqWSItgH8tXQZRbN3WlCurxM6GPGWGiKj6I+L74Ury1 V2UC7NeqzNxXgzpZzMSOtQ4= X-Google-Smtp-Source: ABdhPJypA8sSHoULmOCCwUD3OHbt1Ul5hiuRGxqEGYho/G+7U8bzYaHrQ+DCAWnWEGVQSCiZbClf1w== X-Received: by 2002:adf:d1e7:0:b0:215:2126:dede with SMTP id g7-20020adfd1e7000000b002152126dedemr41966585wrd.297.1654947563600; Sat, 11 Jun 2022 04:39:23 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id g15-20020a05600c4ecf00b0039c4945c753sm6574198wmq.39.2022.06.11.04.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 04:39:23 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stefanberzl@gmail.com, dlatypov@google.com, kunit-dev@googlegroups.com, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v4 3/4] HID: uclogic: Allow to generate frame templates Date: Sat, 11 Jun 2022 13:39:13 +0200 Message-Id: <20220611113914.355577-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611113914.355577-1-jose.exposito89@gmail.com> References: <20220611113914.355577-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add a new template placeholder to allow configuring the number of buttons in the drawing tablet frame and update the KUnit tests to cover the new case. Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-rdesc-test.c | 36 ++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 14 ++++++++--- drivers/hid/hid-uclogic-rdesc.h | 6 +++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-uclogic-rdesc-test.c b/drivers/hid/hid-uclogic-rdesc-test.c index ded59e226230..ebebffef5f8a 100644 --- a/drivers/hid/hid-uclogic-rdesc-test.c +++ b/drivers/hid/hid-uclogic-rdesc-test.c @@ -31,6 +31,10 @@ static const s32 params_pen_some[] = { [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB, }; +static const s32 params_frame_all[UCLOGIC_RDESC_PH_ID_NUM] = { + [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0xFF, +}; + static const __u8 template_empty[] = { }; static const __u8 template_small[] = { 0x00 }; static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D }; @@ -39,6 +43,10 @@ static const __u8 template_pen_ph_end[] = { 0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD }; +static const __u8 template_btn_ph_end[] = { + 0xAA, 0xBB, UCLOGIC_RDESC_FRAME_PH_BTN_HEAD +}; + static const __u8 template_pen_all_params[] = { UCLOGIC_RDESC_PEN_PH(X_LM), 0x47, UCLOGIC_RDESC_PEN_PH(X_PM), @@ -55,6 +63,18 @@ static const __u8 expected_pen_all_params[] = { 0x00, 0xEE, 0x00, 0x00, 0x00, }; +static const __u8 template_frame_all_params[] = { + 0x01, 0x02, + UCLOGIC_RDESC_FRAME_PH_BTN, + 0x99, +}; + +static const __u8 expected_frame_all_params[] = { + 0x01, 0x02, + 0x2A, 0xFF, 0x00, + 0x99, +}; + static const __u8 template_pen_some_params[] = { 0x01, 0x02, UCLOGIC_RDESC_PEN_PH(X_LM), @@ -108,6 +128,14 @@ static struct uclogic_template_case uclogic_template_cases[] = { .param_num = ARRAY_SIZE(params_pen_all), .expected = template_pen_ph_end, }, + { + .name = "Frame button placeholder at the end, without ID", + .template = template_btn_ph_end, + .template_size = sizeof(template_btn_ph_end), + .param_list = params_frame_all, + .param_num = ARRAY_SIZE(params_frame_all), + .expected = template_btn_ph_end, + }, { .name = "All params present in the pen template", .template = template_pen_all_params, @@ -116,6 +144,14 @@ static struct uclogic_template_case uclogic_template_cases[] = { .param_num = ARRAY_SIZE(params_pen_all), .expected = expected_pen_all_params, }, + { + .name = "All params present in the frame template", + .template = template_frame_all_params, + .template_size = sizeof(template_frame_all_params), + .param_list = params_frame_all, + .param_num = ARRAY_SIZE(params_frame_all), + .expected = expected_frame_all_params, + }, { .name = "Some params present in the pen template (complete param list)", .template = template_pen_some_params, diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 7126fba80968..3fb84ac492b4 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -979,7 +979,7 @@ const size_t uclogic_rdesc_xppen_deco01_frame_size = * uclogic_rdesc_template_apply() - apply report descriptor parameters to a * report descriptor template, creating a report descriptor. Copies the * template over to the new report descriptor and replaces every occurrence of - * UCLOGIC_RDESC_PEN_PH_HEAD, followed by an index byte, with the value from the + * the template placeholders, followed by an index byte, with the value from the * parameter list at that index. * * @template_ptr: Pointer to the template buffer. @@ -996,6 +996,7 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, const s32 *param_list, size_t param_num) { + static const __u8 btn_head[] = {UCLOGIC_RDESC_FRAME_PH_BTN_HEAD}; static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD}; __u8 *rdesc_ptr; __u8 *p; @@ -1005,12 +1006,19 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, if (rdesc_ptr == NULL) return NULL; - for (p = rdesc_ptr; p + sizeof(pen_head) < rdesc_ptr + template_size;) { - if (memcmp(p, pen_head, sizeof(pen_head)) == 0 && + for (p = rdesc_ptr; p + sizeof(btn_head) < rdesc_ptr + template_size;) { + if (p + sizeof(pen_head) < rdesc_ptr + template_size && + memcmp(p, pen_head, sizeof(pen_head)) == 0 && p[sizeof(pen_head)] < param_num) { v = param_list[p[sizeof(pen_head)]]; put_unaligned(cpu_to_le32(v), (s32 *)p); p += sizeof(pen_head) + 1; + } else if (memcmp(p, btn_head, sizeof(btn_head)) == 0 && + p[sizeof(btn_head)] < param_num) { + v = param_list[p[sizeof(btn_head)]]; + put_unaligned((__u8)0x2A, p); /* Usage Maximum */ + put_unaligned_le16((__force u16)cpu_to_le16(v), p + 1); + p += sizeof(btn_head) + 1; } else { p++; } diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index 9d37090c39d1..3d78299f082d 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -82,6 +82,7 @@ extern const size_t uclogic_rdesc_twha60_fixed1_size; /* Report descriptor template placeholder head */ #define UCLOGIC_RDESC_PEN_PH_HEAD 0xFE, 0xED, 0x1D +#define UCLOGIC_RDESC_FRAME_PH_BTN_HEAD 0xFE, 0xED /* Apply report descriptor parameters to a report descriptor template */ extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr, @@ -96,6 +97,7 @@ enum uclogic_rdesc_ph_id { UCLOGIC_RDESC_PEN_PH_ID_Y_LM, UCLOGIC_RDESC_PEN_PH_ID_Y_PM, UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM, + UCLOGIC_RDESC_FRAME_PH_ID_UM, UCLOGIC_RDESC_PH_ID_NUM }; @@ -103,6 +105,10 @@ enum uclogic_rdesc_ph_id { #define UCLOGIC_RDESC_PEN_PH(_ID) \ UCLOGIC_RDESC_PEN_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID +/* Report descriptor frame buttons template placeholder */ +#define UCLOGIC_RDESC_FRAME_PH_BTN \ + UCLOGIC_RDESC_FRAME_PH_BTN_HEAD, UCLOGIC_RDESC_FRAME_PH_ID_UM + /* Report ID for v1 pen reports */ #define UCLOGIC_RDESC_V1_PEN_ID 0x07 From patchwork Sat Jun 11 11:39:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 581211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2470C43334 for ; Sat, 11 Jun 2022 11:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233248AbiFKLjk (ORCPT ); Sat, 11 Jun 2022 07:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233108AbiFKLjb (ORCPT ); Sat, 11 Jun 2022 07:39:31 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48DA331917; Sat, 11 Jun 2022 04:39:30 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id a15so1622196wrh.2; Sat, 11 Jun 2022 04:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E6LUcOWx1z2poXLh/BFADj8qF2w3QGSPYJH8IboePfI=; b=bZ7u0cc3U6L/BONVClV8csKlcT8JX0Z+B6XuWLlENVKVv7ckr53eYpR2H8GQwDxjWn 4KpKjr5WCdSHkHKC1TjVDeUS6zFF7gJ0DlkD2l6Yefa211poMU7EDvFHX00iVbbv6hL2 LlegBDdFtIXu0Sr/bM51w8tsn8Mf3lKHINuMOnyMFqoQFBrGCGkFYFJnTQzfUn1a17q0 YZJEbWl9WgTc9iWml60gea9rI6z6Jx13OqeB8i2u0i6ckCIXs4vuHCaU1Tj1PkVCgF+6 myNfBMrDHXQ2vAJ/wIIj6dglwQA0uaWrluGVfNjqdattLTOrqWTPZzFhpT5rBXvML9pY ED/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E6LUcOWx1z2poXLh/BFADj8qF2w3QGSPYJH8IboePfI=; b=Y7qG6dBPqOoNIw4WMZWN+GbC4dQmLpGaHdXItC2pjyt3aHHhH5gARbwKtzKLK5/paR 4nA3KoZAPjyFP1CDdT/byUMTh411BCXNzwXo/Asm8OkCL5d1NlOixd4lJ+jHf60NO9sO +j6akk3BlBOpKf46D4ig2NGPBaoigH6wOXnVhut/MNQlTt92lhVb8hllW5ddaDGvyODY 7vEXKdiqbcMkNcDtrf4An1Y1bkJwzgLbJ2mRbNdxVh0NO3PVM991vzzPpW0RE66O7laP 0wS61ICB00RyF2TQxVxK1lTGI9A2B4us7+MlbVXeC29TNTkY+RxkYkQNyCLEQnTctSBt 2cFg== X-Gm-Message-State: AOAM5304e1wVliWB6brRORbW6AKwrdW4MGppCSeU+xlD73gRTb4D2ecR 40omoIEf11FYNnU5iqYZDz0= X-Google-Smtp-Source: ABdhPJy4tkT8OmzrHbi4TtndOVJI8UKfigZjThP1+tpdBOqxJ1KLc43vo9dZ27GgyZ2Cc8zdFhzv5Q== X-Received: by 2002:adf:f00c:0:b0:210:3430:5fdd with SMTP id j12-20020adff00c000000b0021034305fddmr48045739wro.448.1654947568727; Sat, 11 Jun 2022 04:39:28 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id g15-20020a05600c4ecf00b0039c4945c753sm6574198wmq.39.2022.06.11.04.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 04:39:28 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stefanberzl@gmail.com, dlatypov@google.com, kunit-dev@googlegroups.com, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v4 4/4] HID: uclogic: Add support for XP-PEN Deco L Date: Sat, 11 Jun 2022 13:39:14 +0200 Message-Id: <20220611113914.355577-5-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220611113914.355577-1-jose.exposito89@gmail.com> References: <20220611113914.355577-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The XP-PEN Deco L (UGEE) needs to be initialized by sending a buffer of magic data, discovered by sniffing the Windows driver traffic. In order to differentiate UGEE tablets that need this kind of initialization from the previous ones, name them v2 internally and create an entry point for them. After initialization, the template report descriptors can be discovered by parsing a string descriptor, similar to the one exposed by HUION v1 devices. Add all the required elements to support the device. Signed-off-by: José Expósito --- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-uclogic-core.c | 2 + drivers/hid/hid-uclogic-params.c | 197 +++++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 102 ++++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 8 ++ 5 files changed, 310 insertions(+) diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index d9eb676abe96..139910034c17 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -1278,6 +1278,7 @@ #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540 0x0075 #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640 0x0094 #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01 0x0042 +#define USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L 0x0935 #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06 0x0078 #define USB_DEVICE_ID_UGEE_TABLET_G5 0x0074 #define USB_DEVICE_ID_UGEE_TABLET_EX07S 0x0071 diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index c0fe66e50c58..47a17375c7fc 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -521,6 +521,8 @@ static const struct hid_device_id uclogic_devices[] = { USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640) }, { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01) }, + { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, + USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L) }, { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06) }, { } diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index b43142f98a8b..f24a4aca7920 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1002,6 +1002,197 @@ static int uclogic_params_huion_init(struct uclogic_params *params, return rc; } +/** + * uclogic_probe_interface() - some tablets, like the Parblo A610 PLUS V2 or + * the XP-PEN Deco Mini 7, need to be initialized by sending them magic data. + * + * @hdev: The HID device of the tablet interface to initialize and get + * parameters from. Cannot be NULL. + * @magic_arr: The magic data that should be sent to probe the interface. + * Cannot be NULL. + * @magic_size: Size of the magic data. + * @endpoint: Endpoint where the magic data should be sent. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_probe_interface(struct hid_device *hdev, u8 *magic_arr, + int magic_size, int endpoint) +{ + struct usb_device *udev; + unsigned int pipe = 0; + int sent; + u8 *buf = NULL; + int rc = 0; + + if (!hdev || !magic_arr) { + rc = -EINVAL; + goto cleanup; + } + + buf = kmemdup(magic_arr, magic_size, GFP_KERNEL); + if (!buf) { + rc = -ENOMEM; + goto cleanup; + } + + udev = hid_to_usb_dev(hdev); + pipe = usb_sndintpipe(udev, endpoint); + + rc = usb_interrupt_msg(udev, pipe, buf, magic_size, &sent, 1000); + if (rc || sent != magic_size) { + hid_err(hdev, "Interface probing failed: %d\n", rc); + rc = -1; + goto cleanup; + } + + rc = 0; +cleanup: + kfree(buf); + return rc; +} + +/** + * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by + * discovering their parameters. + * + * These tables, internally designed as v2 to differentiate them from older + * models, expect a payload of magic data in orther to be switched to the fully + * functional mode and expose their parameters in a similar way to the + * information present in uclogic_params_pen_init_v1() but with some + * differences. + * + * @params: Parameters to fill in (to be cleaned with + * uclogic_params_cleanup()). Not modified in case of error. + * Cannot be NULL. + * @hdev: The HID device of the tablet interface to initialize and get + * parameters from. Cannot be NULL. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_params_ugee_v2_init(struct uclogic_params *params, + struct hid_device *hdev) +{ + int rc = 0; + struct usb_interface *iface; + __u8 bInterfaceNumber; + const int str_desc_len = 12; + __u8 *str_desc = NULL; + __u8 *rdesc_pen = NULL; + __u8 *rdesc_frame = NULL; + s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; + s32 resolution; + __u8 magic_arr[] = { + 0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + /* The resulting parameters (noop) */ + struct uclogic_params p = {0, }; + + if (!params || !hdev) { + rc = -EINVAL; + goto cleanup; + } + + iface = to_usb_interface(hdev->dev.parent); + bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + if (bInterfaceNumber != 2) { + uclogic_params_init_invalid(&p); + goto output; + } + + /* + * Initialize the interface by sending magic data. + * The specific data was discovered by sniffing the Windows driver + * traffic. + */ + rc = uclogic_probe_interface(hdev, magic_arr, sizeof(magic_arr), 0x03); + if (rc) { + uclogic_params_init_invalid(&p); + goto output; + } + + /* + * Read the string descriptor containing pen and frame parameters. + * The specific string descriptor and data were discovered by sniffing + * the Windows driver traffic. + */ + rc = uclogic_params_get_str_desc(&str_desc, hdev, 100, str_desc_len); + if (rc != str_desc_len) { + hid_err(hdev, "failed retrieving pen and frame parameters: %d\n", rc); + uclogic_params_init_invalid(&p); + goto output; + } + + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = + get_unaligned_le16(str_desc + 2); + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = + get_unaligned_le16(str_desc + 4); + desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM] = str_desc[6]; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = + get_unaligned_le16(str_desc + 8); + resolution = get_unaligned_le16(str_desc + 10); + if (resolution == 0) { + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0; + } else { + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 / + resolution; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 / + resolution; + } + kfree(str_desc); + str_desc = NULL; + + /* Initialize the pen interface */ + rdesc_pen = uclogic_rdesc_template_apply( + uclogic_rdesc_ugee_v2_pen_template_arr, + uclogic_rdesc_ugee_v2_pen_template_size, + desc_params, ARRAY_SIZE(desc_params)); + if (!rdesc_pen) { + rc = -ENOMEM; + goto cleanup; + } + + p.pen.desc_ptr = rdesc_pen; + p.pen.desc_size = uclogic_rdesc_ugee_v2_pen_template_size; + p.pen.id = 0x02; + p.pen.subreport_list[0].value = 0xf0; + p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID; + + /* Initialize the frame interface */ + rdesc_frame = uclogic_rdesc_template_apply( + uclogic_rdesc_ugee_v2_frame_btn_template_arr, + uclogic_rdesc_ugee_v2_frame_btn_template_size, + desc_params, ARRAY_SIZE(desc_params)); + if (!rdesc_frame) { + rc = -ENOMEM; + goto cleanup; + } + + rc = uclogic_params_frame_init_with_desc(&p.frame_list[0], + rdesc_frame, + uclogic_rdesc_ugee_v2_frame_btn_template_size, + UCLOGIC_RDESC_V1_FRAME_ID); + kfree(rdesc_frame); + if (rc) { + uclogic_params_init_invalid(&p); + goto output; + } + +output: + /* Output parameters */ + memcpy(params, &p, sizeof(*params)); + memset(&p, 0, sizeof(p)); + rc = 0; +cleanup: + kfree(str_desc); + uclogic_params_cleanup(&p); + return rc; +} + /** * uclogic_params_init() - initialize a tablet interface and discover its * parameters. @@ -1237,6 +1428,12 @@ int uclogic_params_init(struct uclogic_params *params, uclogic_params_init_invalid(&p); } break; + case VID_PID(USB_VENDOR_ID_UGEE, + USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L): + rc = uclogic_params_ugee_v2_init(&p, hdev); + if (rc != 0) + goto cleanup; + break; case VID_PID(USB_VENDOR_ID_TRUST, USB_DEVICE_ID_TRUST_PANORA_TABLET): case VID_PID(USB_VENDOR_ID_UGEE, diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 3fb84ac492b4..3d68e8b0784d 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -859,6 +859,108 @@ const __u8 uclogic_rdesc_v2_frame_dial_arr[] = { const size_t uclogic_rdesc_v2_frame_dial_size = sizeof(uclogic_rdesc_v2_frame_dial_arr); +/* Fixed report descriptor template for UGEE v2 pen reports */ +const __u8 uclogic_rdesc_ugee_v2_pen_template_arr[] = { + 0x05, 0x0d, /* Usage Page (Digitizers), */ + 0x09, 0x01, /* Usage (Digitizer), */ + 0xa1, 0x01, /* Collection (Application), */ + 0x85, 0x02, /* Report ID (2), */ + 0x09, 0x20, /* Usage (Stylus), */ + 0xa1, 0x00, /* Collection (Physical), */ + 0x09, 0x42, /* Usage (Tip Switch), */ + 0x09, 0x44, /* Usage (Barrel Switch), */ + 0x09, 0x46, /* Usage (Tablet Pick), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x03, /* Report Count (3), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x03, /* Input (Constant, Variable), */ + 0x09, 0x32, /* Usage (In Range), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x03, /* Input (Constant, Variable), */ + 0x75, 0x10, /* Report Size (16), */ + 0x95, 0x01, /* Report Count (1), */ + 0x35, 0x00, /* Physical Minimum (0), */ + 0xa4, /* Push, */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x30, /* Usage (X), */ + 0x65, 0x13, /* Unit (Inch), */ + 0x55, 0x0d, /* Unit Exponent (-3), */ + 0x27, UCLOGIC_RDESC_PEN_PH(X_LM), + /* Logical Maximum (PLACEHOLDER), */ + 0x47, UCLOGIC_RDESC_PEN_PH(X_PM), + /* Physical Maximum (PLACEHOLDER), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x31, /* Usage (Y), */ + 0x27, UCLOGIC_RDESC_PEN_PH(Y_LM), + /* Logical Maximum (PLACEHOLDER), */ + 0x47, UCLOGIC_RDESC_PEN_PH(Y_PM), + /* Physical Maximum (PLACEHOLDER), */ + 0x81, 0x02, /* Input (Variable), */ + 0xb4, /* Pop, */ + 0x09, 0x30, /* Usage (Tip Pressure), */ + 0x45, 0x00, /* Physical Maximum (0), */ + 0x27, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM), + /* Logical Maximum (PLACEHOLDER), */ + 0x75, 0x0D, /* Report Size (13), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x03, /* Report Count (3), */ + 0x81, 0x01, /* Input (Constant), */ + 0x09, 0x3d, /* Usage (X Tilt), */ + 0x35, 0xC3, /* Physical Minimum (-61), */ + 0x45, 0x3C, /* Physical Maximum (60), */ + 0x15, 0xC3, /* Logical Minimum (-61), */ + 0x25, 0x3C, /* Logical Maximum (60), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x3e, /* Usage (Y Tilt), */ + 0x35, 0xC3, /* Physical Minimum (-61), */ + 0x45, 0x3C, /* Physical Maximum (60), */ + 0x15, 0xC3, /* Logical Minimum (-61), */ + 0x25, 0x3C, /* Logical Maximum (60), */ + 0x81, 0x02, /* Input (Variable), */ + 0xc0, /* End Collection, */ + 0xc0, /* End Collection */ +}; +const size_t uclogic_rdesc_ugee_v2_pen_template_size = + sizeof(uclogic_rdesc_ugee_v2_pen_template_arr); + +/* Fixed report descriptor template for UGEE v2 frame reports (buttons only) */ +const __u8 uclogic_rdesc_ugee_v2_frame_btn_template_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x07, /* Usage (Keypad), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, UCLOGIC_RDESC_V1_FRAME_ID, + /* Report ID, */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x09, 0x39, /* Usage (Tablet Function Keys), */ + 0xA0, /* Collection (Physical), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x08, /* Report Count (8), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x19, 0x01, /* Usage Minimum (01h), */ + UCLOGIC_RDESC_FRAME_PH_BTN, + /* Usage Maximum (PLACEHOLDER), */ + 0x95, 0x0A, /* Report Count (10), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x46, /* Report Count (70), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size = + sizeof(uclogic_rdesc_ugee_v2_frame_btn_template_arr); + /* Fixed report descriptor for Ugee EX07 frame */ const __u8 uclogic_rdesc_ugee_ex07_frame_arr[] = { 0x05, 0x01, /* Usage Page (Desktop), */ diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index 3d78299f082d..86e64a9ee6bd 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -161,6 +161,14 @@ extern const size_t uclogic_rdesc_v2_frame_dial_size; /* Device ID byte offset in v2 frame dial reports */ #define UCLOGIC_RDESC_V2_FRAME_DIAL_DEV_ID_BYTE 0x4 +/* Fixed report descriptor template for UGEE v2 pen reports */ +extern const __u8 uclogic_rdesc_ugee_v2_pen_template_arr[]; +extern const size_t uclogic_rdesc_ugee_v2_pen_template_size; + +/* Fixed report descriptor template for UGEE v2 frame reports (buttons only) */ +extern const __u8 uclogic_rdesc_ugee_v2_frame_btn_template_arr[]; +extern const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size; + /* Fixed report descriptor for Ugee EX07 frame */ extern const __u8 uclogic_rdesc_ugee_ex07_frame_arr[]; extern const size_t uclogic_rdesc_ugee_ex07_frame_size;