From patchwork Sun Jul 17 14:43:27 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: 591557 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 96D65C433EF for ; Sun, 17 Jul 2022 14:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229654AbiGQOnn (ORCPT ); Sun, 17 Jul 2022 10:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231434AbiGQOnl (ORCPT ); Sun, 17 Jul 2022 10:43:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 732FFDF66; Sun, 17 Jul 2022 07:43:39 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id c18so727847wmh.1; Sun, 17 Jul 2022 07:43:39 -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=hXEApsgmJM0YpgsYBqtez7wZ8rBpB7fQbxI7//Qi7zM=; b=ojJqo8IOKmmUSk/fA9YV63avtcdtgVb8kpZp7yC8z17TJSoGl1hl3ehBANPKg7PyZF bQznaBjZ8QPmUEru4GIfBLXXIParP3ArjiSruil5I6ZJDdSg+6PIv7JuiAvAyB2Jdj5r mOk8lH1xj7npm0aIh5CMLlFxPEhr+gjeZBsdV2k0YjVli7qppsqYUL0P88cC+2V4Tvf8 y53SV0/dTdKB/Vnf+mll8V0gTd8RWYlePnPrhh3GFw24vvt0ewHR3ssErj/wibJFyedK sH6fZwPDLupY5Mx/0QsLt1Xi0orVEbGXfcRk/pCb+SIVR9cxLJM3DqD4Lh3vh46ONsNJ 0lZg== 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=hXEApsgmJM0YpgsYBqtez7wZ8rBpB7fQbxI7//Qi7zM=; b=j457/7p7aSwgBdzS7mRrqDIg73U02KyGJ2f3I1fdWMSZbadKyTR2eDzYKUdUbhWnAE blsbZQqLs9VOIT5i0qJ2N4SDPjdWSyh/S/HhrlFtzIUC5/0UcOi0JkOvVe4fT27MrLWo wSZ/dqOMVN67kNxAUDllM7IpK0N0YTkI+/+23U6rsf5sqwwlAkbNNoxez5Sxa6SiQAL5 Kbn7NhA0/YmCB8Oacmc1ruTOYNsyY0PpdVZ4OlhdKmGVqnng29dcJX1zNOE+ojFph8oa D6WzhRcjOD51L4dbKVKWTcVV/GnP4CLYo27bZ1D371lqXPclOxGJ1BdOLQvmFEqBpnRt CPCw== X-Gm-Message-State: AJIora+ly3/fvD7cVM8GXj3VtDzQAbymhHrLIKE800DDWYNqsLslGx5R +BjwKV3BfVBVmOeArLVdFs8= X-Google-Smtp-Source: AGRyM1tSA49cvfq77Uxw6Je3aDDDizMBN9dWv1uxPVMqXw84zL+aeXKyPy5shPMgY+JSEMwtNeFpwg== X-Received: by 2002:a05:600c:28d:b0:3a2:d06d:3894 with SMTP id 13-20020a05600c028d00b003a2d06d3894mr29101031wmk.51.1658069017974; Sun, 17 Jul 2022 07:43:37 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:37 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= , Daniel Latypov Subject: [PATCH v2 1/7] HID: uclogic: KUnit best practices and naming conventions Date: Sun, 17 Jul 2022 16:43:27 +0200 Message-Id: <20220717144333.251190-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The KUnit documentation [1] suggests allowing build tests as a module. In addition, it is recommended [2] to use snake case names for kunit_suite and test cases. Change the Kconfig entry from bool to tristate and stick to the naming conventions to avoid style issues with future tests. Link: https://docs.kernel.org/dev-tools/kunit/style.html#test-kconfig-entries [1] Link: https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html [2] Acked-by: Daniel Latypov Signed-off-by: José Expósito --- drivers/hid/Kconfig | 2 +- drivers/hid/Makefile | 3 ++- drivers/hid/hid-uclogic-rdesc-test.c | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 6ce92830b5d1..36a17958493f 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1307,7 +1307,7 @@ config HID_MCP2221 will be called hid-mcp2221.ko. config HID_KUNIT_TEST - bool "KUnit tests for HID" if !KUNIT_ALL_TESTS + tristate "KUnit tests for HID" if !KUNIT_ALL_TESTS depends on KUNIT=y depends on HID_UCLOGIC default KUNIT_ALL_TESTS diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index b0bef8098139..82d8fd97d96c 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -144,8 +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-test-objs := hid-uclogic-rdesc.o \ hid-uclogic-rdesc-test.o +obj-$(CONFIG_HID_KUNIT_TEST) += hid-uclogic-test.o obj-$(CONFIG_USB_HID) += usbhid/ obj-$(CONFIG_USB_MOUSE) += usbhid/ diff --git a/drivers/hid/hid-uclogic-rdesc-test.c b/drivers/hid/hid-uclogic-rdesc-test.c index ebebffef5f8a..3971a0854c3e 100644 --- a/drivers/hid/hid-uclogic-rdesc-test.c +++ b/drivers/hid/hid-uclogic-rdesc-test.c @@ -97,7 +97,7 @@ static const __u8 template_params_none[] = { static struct uclogic_template_case uclogic_template_cases[] = { { - .name = "Empty template", + .name = "empty_template", .template = template_empty, .template_size = sizeof(template_empty), .param_list = params_pen_all, @@ -105,7 +105,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = template_empty, }, { - .name = "Template smaller than the placeholder", + .name = "template_smaller_than_the_placeholder", .template = template_small, .template_size = sizeof(template_small), .param_list = params_pen_all, @@ -113,7 +113,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = template_small, }, { - .name = "No placeholder", + .name = "no_placeholder", .template = template_no_ph, .template_size = sizeof(template_no_ph), .param_list = params_pen_all, @@ -121,7 +121,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = template_no_ph, }, { - .name = "Pen placeholder at the end, without ID", + .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, @@ -129,7 +129,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = template_pen_ph_end, }, { - .name = "Frame button placeholder at the end, without ID", + .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, @@ -137,7 +137,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = template_btn_ph_end, }, { - .name = "All params present in the pen template", + .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, @@ -145,7 +145,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = expected_pen_all_params, }, { - .name = "All params present in the frame template", + .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, @@ -153,7 +153,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = expected_frame_all_params, }, { - .name = "Some params present in the pen template (complete param list)", + .name = "some_params_present_in_the_pen_template_with_complete_param_list", .template = template_pen_some_params, .template_size = sizeof(template_pen_some_params), .param_list = params_pen_all, @@ -161,7 +161,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = expected_pen_some_params, }, { - .name = "Some params present in the pen template (incomplete param list)", + .name = "some_params_present_in_the_pen_template_with_incomplete_param_list", .template = template_pen_some_params, .template_size = sizeof(template_pen_some_params), .param_list = params_pen_some, @@ -169,7 +169,7 @@ static struct uclogic_template_case uclogic_template_cases[] = { .expected = expected_pen_some_params, }, { - .name = "No params present in the template", + .name = "no_params_present_in_the_template", .template = template_params_none, .template_size = sizeof(template_params_none), .param_list = params_pen_some, @@ -208,7 +208,7 @@ static struct kunit_case hid_uclogic_rdesc_test_cases[] = { }; static struct kunit_suite hid_uclogic_rdesc_test_suite = { - .name = "hid-uclogic-rdesc-test", + .name = "hid_uclogic_rdesc_test", .test_cases = hid_uclogic_rdesc_test_cases, }; From patchwork Sun Jul 17 14:43:28 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: 591556 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 6F815CCA47B for ; Sun, 17 Jul 2022 14:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbiGQOnn (ORCPT ); Sun, 17 Jul 2022 10:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbiGQOnm (ORCPT ); Sun, 17 Jul 2022 10:43:42 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F628EE02; Sun, 17 Jul 2022 07:43:40 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id f24-20020a1cc918000000b003a30178c022so6099513wmb.3; Sun, 17 Jul 2022 07:43:40 -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=rLL2RudRcmj7MtRur/Ij0ZhLJLzj6mBpPVyBeIpUBA0=; b=ALihYUCxiOAcV8lRAmyxITsMcEB6cQWeDaiXq64PCXPC0nT1pmNFu5JLv7m+7VqOLh DSBPkexB43/7e9NUTLckJLWQQPfA78aLcJTUM/FJvsM1vlsxiu5Zi+bJh/2c6QL/isGr c9DfM1s1K+B+bSkGiRisIAYCPGogR4KW4qBBPNHnZ9Ac/1c9i4RdDLM9mg+KBK3oAOPF an+6JY8JnrHS/Kd9D7fw8Ne/CzDDPA3Da9zmypSNsH9Lf9lT8iLnMQ3zwwmHFOhwA4DO jzO/Xe0tReaEbTGa8NsBf8ZeV4TZekvtwuTbZhq8NkgwlmupA4D4nJKaq21QpX1jXrwO vViA== 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=rLL2RudRcmj7MtRur/Ij0ZhLJLzj6mBpPVyBeIpUBA0=; b=Jrt/ygJP9LeiCozJfUJsCv9BYcofqCF5xbXgzy5+DafDQMN8uZFiNAN0mDtdaLN33Y yk30B5RHgvik+rCw5q+zf1eeQv5+1nw/zunE1PMoWWRp9HkGNrT7vGvi8cidpC7h+8aR 2y+g+eKZxxxChsH0YoP40Bq0fvCJmFzsPR1uVXsy98/vhaj3uoB/Tu2lF8HuPmkqdGb+ qM4ePGKUlIbH6BvozTZoDK+dCLaAYXsAMomxApy8iDtN4dijUdlCNn3VEp7kP/Zw4N1d 1w/7Tl2xyxX+0g/lTaF1wDHBEsBVBQggaolGSmQf8Cvj8N4ztsHlhXMp74WrosPD6g/2 SDFw== X-Gm-Message-State: AJIora/oi71UyzhAjMbFrt9SlgEfDXu4hvoQcBG32IbS+ietY6I7e0YD EIEun1AJb2dqyBTTQ2NdFD0= X-Google-Smtp-Source: AGRyM1tsYFohXLe/POU6X9ZNXGwAV+g05xOhqP0cruPQOvIBZR3pmp+QqqZoKDQvRQsUfnXdqwGFHQ== X-Received: by 2002:a1c:cc13:0:b0:3a2:d01e:54a1 with SMTP id h19-20020a1ccc13000000b003a2d01e54a1mr23078148wmb.164.1658069018798; Sun, 17 Jul 2022 07:43:38 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:38 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 2/7] HID: uclogic: Refactor UGEE v2 string descriptor parsing Date: Sun, 17 Jul 2022 16:43:28 +0200 Message-Id: <20220717144333.251190-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The UGEE v2 tablets expose a string descriptor with their capabilities. Move the code used to parse the descriptors and generate a parameter list from it to its own function and add KUnit tests to validate the parser. Tested-by: Jouke Witteveen Signed-off-by: José Expósito --- drivers/hid/Makefile | 1 + drivers/hid/hid-uclogic-params-test.c | 159 ++++++++++++++++++++++++++ drivers/hid/hid-uclogic-params.c | 86 ++++++++++---- 3 files changed, 226 insertions(+), 20 deletions(-) create mode 100644 drivers/hid/hid-uclogic-params-test.c diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 82d8fd97d96c..fe69dece2a46 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -145,6 +145,7 @@ obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o obj-$(CONFIG_HID_SENSOR_CUSTOM_SENSOR) += hid-sensor-custom.o hid-uclogic-test-objs := hid-uclogic-rdesc.o \ + hid-uclogic-params.o \ hid-uclogic-rdesc-test.o obj-$(CONFIG_HID_KUNIT_TEST) += hid-uclogic-test.o diff --git a/drivers/hid/hid-uclogic-params-test.c b/drivers/hid/hid-uclogic-params-test.c new file mode 100644 index 000000000000..9f043f2ab387 --- /dev/null +++ b/drivers/hid/hid-uclogic-params-test.c @@ -0,0 +1,159 @@ +// 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" + +#define MAX_STR_DESC_SIZE 14 + +struct uclogic_parse_ugee_v2_desc_case { + const char *name; + int res; + const __u8 str_desc[MAX_STR_DESC_SIZE]; + size_t str_desc_size; + const s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; +}; + +static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] = { + { + .name = "invalid_str_desc", + .res = -EINVAL, + .str_desc = {}, + .str_desc_size = 0, + .desc_params = {}, + }, + { + .name = "resolution_with_value_0", + .res = 0, + .str_desc = { + 0x0E, 0x03, + 0x70, 0xB2, + 0x10, 0x77, + 0x08, + 0x00, + 0xFF, 0x1F, + 0x00, 0x00, + }, + .str_desc_size = 12, + .desc_params = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB270, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0, + [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7710, + [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0, + [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, + [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08, + }, + }, + /* XP-PEN Deco L str_desc: Frame with 8 buttons */ + { + .name = "frame_type_buttons", + .res = 0, + .str_desc = { + 0x0E, 0x03, + 0x70, 0xB2, + 0x10, 0x77, + 0x08, + 0x00, + 0xFF, 0x1F, + 0xD8, 0x13, + }, + .str_desc_size = 12, + .desc_params = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB270, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2320, + [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7710, + [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x1770, + [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, + [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08, + }, + }, + /* PARBLO A610 PRO str_desc: Frame with 9 buttons and dial */ + { + .name = "frame_type_dial", + .res = 0, + .str_desc = { + 0x0E, 0x03, + 0x96, 0xC7, + 0xF9, 0x7C, + 0x09, + 0x01, + 0xFF, 0x1F, + 0xD8, 0x13, + }, + .str_desc_size = 12, + .desc_params = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xC796, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2749, + [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7CF9, + [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x1899, + [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, + [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x09, + }, + }, +}; + +static void uclogic_parse_ugee_v2_desc_case_desc(struct uclogic_parse_ugee_v2_desc_case *t, + char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(uclogic_parse_ugee_v2_desc, uclogic_parse_ugee_v2_desc_cases, + uclogic_parse_ugee_v2_desc_case_desc); + +static void uclogic_parse_ugee_v2_desc_test(struct kunit *test) +{ + int res; + s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; + const struct uclogic_parse_ugee_v2_desc_case *params = test->param_value; + + res = uclogic_params_parse_ugee_v2_desc(params->str_desc, + params->str_desc_size, + desc_params, + ARRAY_SIZE(desc_params)); + KUNIT_ASSERT_EQ(test, res, params->res); + + if (res) + return; + + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM], + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM]); + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM], + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM]); + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM], + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM]); + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM], + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM]); + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM], + desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM]); + KUNIT_EXPECT_EQ(test, + params->desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM], + desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM]); +} + +static struct kunit_case hid_uclogic_params_test_cases[] = { + KUNIT_CASE_PARAM(uclogic_parse_ugee_v2_desc_test, + uclogic_parse_ugee_v2_desc_gen_params), + {} +}; + +static struct kunit_suite hid_uclogic_params_test_suite = { + .name = "hid_uclogic_params_test", + .test_cases = hid_uclogic_params_test_cases, +}; + +kunit_test_suite(hid_uclogic_params_test_suite); + +MODULE_DESCRIPTION("KUnit tests for the UC-Logic driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("José Expósito "); diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index f24a4aca7920..ab54f0125e05 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1052,6 +1052,62 @@ static int uclogic_probe_interface(struct hid_device *hdev, u8 *magic_arr, return rc; } +/** + * uclogic_params_parse_ugee_v2_desc - parse the string descriptor containing + * pen and frame parameters returned by UGEE v2 devices. + * + * @str_desc: String descriptor, cannot be NULL. + * @str_desc_size: Size of the string descriptor. + * @desc_params: Output description params list. + * @desc_params_size: Size of the output description params list. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_params_parse_ugee_v2_desc(const __u8 *str_desc, + size_t str_desc_size, + s32 *desc_params, + size_t desc_params_size) +{ + s32 pen_x_lm, pen_y_lm; + s32 pen_x_pm, pen_y_pm; + s32 pen_pressure_lm; + s32 frame_num_buttons; + s32 resolution; + + /* Minimum descriptor length required, maximum seen so far is 14 */ + const int min_str_desc_size = 12; + + if (!str_desc || str_desc_size < min_str_desc_size) + return -EINVAL; + + if (desc_params_size != UCLOGIC_RDESC_PH_ID_NUM) + return -EINVAL; + + pen_x_lm = get_unaligned_le16(str_desc + 2); + pen_y_lm = get_unaligned_le16(str_desc + 4); + frame_num_buttons = str_desc[6]; + pen_pressure_lm = get_unaligned_le16(str_desc + 8); + + resolution = get_unaligned_le16(str_desc + 10); + if (resolution == 0) { + pen_x_pm = 0; + pen_y_pm = 0; + } else { + pen_x_pm = pen_x_lm * 1000 / resolution; + pen_y_pm = pen_y_lm * 1000 / resolution; + } + + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = pen_x_lm; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = pen_x_pm; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = pen_y_lm; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = pen_y_pm; + desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = pen_pressure_lm; + desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM] = frame_num_buttons; + + return 0; +} + /** * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by * discovering their parameters. @@ -1082,7 +1138,6 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, __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 }; @@ -1124,25 +1179,12 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, 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; - } + rc = uclogic_params_parse_ugee_v2_desc(str_desc, str_desc_len, + desc_params, + ARRAY_SIZE(desc_params)); + if (rc) + goto cleanup; + kfree(str_desc); str_desc = NULL; @@ -1513,3 +1555,7 @@ int uclogic_params_init(struct uclogic_params *params, uclogic_params_cleanup(&p); return rc; } + +#ifdef CONFIG_HID_KUNIT_TEST +#include "hid-uclogic-params-test.c" +#endif From patchwork Sun Jul 17 14:43:29 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: 591422 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 600F4CCA481 for ; Sun, 17 Jul 2022 14:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232454AbiGQOnn (ORCPT ); Sun, 17 Jul 2022 10:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbiGQOnm (ORCPT ); Sun, 17 Jul 2022 10:43:42 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1068BEBA; Sun, 17 Jul 2022 07:43:41 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 8-20020a05600c024800b003a2fe343db1so5903052wmj.1; Sun, 17 Jul 2022 07:43:40 -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=5ALxRC4P4NjmMOyYfdVkXxixEevQkN7Xh/olINwZD68=; b=VvAAB8QyKYLPQgDMd5r6mttXiX3QiTnQy4kb571ydYGqAaziRchU31Cx4CuP4aCFEK QeY8UWTCx/rf/n0UDwG7n+JILgukkIrTLXI3pKP6NZ7B8tJu+XCFjJy2RDX+D1oM+03C aZ//LesTCsnpz4JhyuZ7p/BBy0DUS8Yz8fhMRDCtdywDLpxQriQgrBG9/0BW3CRrjd47 DyXOnRIqE+DIJL9w9lwqEPrYxeLd0wNZkpfMoWFMepfSQ+pFAyELM38AJz11p2BM0y79 06Po9B/CMJj/7GOFyapDyzQRppN77WUv/BXlrOsbkt//Etz+ZD3SgChMYZBEc+P+RsQd TjiQ== 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=5ALxRC4P4NjmMOyYfdVkXxixEevQkN7Xh/olINwZD68=; b=0QMdlhGfzqG9dx4+EQ8KUScH7bciD+WiRQHBBENe/X2NKlAcXBajvVNeAAPXw879ui zrqOHALT3MqGxIiHumluUHpeVux8vEvNUT4PZCZUsrksK3AgZo2QqMkMN1jPOVtxpFlE NhA9ySxT+NIl5xKm149hmQMHvxsuO/ZVbjfQaYkZoeYOcePARArBWve97GB7uRlFDpIb 2BFXxbYlDbJErrgX8kwLJMsLspBOKH7CGpczic4qOqCTeeOkUce7a+z3+xKHH0/BI9mF 3q5ZKA59erefz/OY9VO9lYQ8GA0M8vF7svZmHkkaGpUTqDSnktwJt0StiXAszhSlK6gH q1yA== X-Gm-Message-State: AJIora+rdGlROsQRHD48fEucyB+oIjo1LA8Khw/krEp6+DvphLAPaiES Q2SfzTY+xYAuZmu46t+JLgU= X-Google-Smtp-Source: AGRyM1ueRgpzktK9Xw4yNDaYjfhXahRrzmtsLspuZy2gw58HpwNS8YEMWpTe6DkntB0N8q5Rzhd13w== X-Received: by 2002:a05:600c:3ca4:b0:3a0:1825:2e29 with SMTP id bg36-20020a05600c3ca400b003a018252e29mr22397194wmb.11.1658069019625; Sun, 17 Jul 2022 07:43:39 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:39 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 3/7] HID: uclogic: Refactor UGEE v2 frame initialization Date: Sun, 17 Jul 2022 16:43:29 +0200 Message-Id: <20220717144333.251190-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org At the moment, the driver only supports UGEE v2 devices that have buttons in their frames. In order to support other types of frames in the future, move the code used to initialize this kind of frames to its own function. Tested-by: Jouke Witteveen Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params.c | 55 +++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index ab54f0125e05..7b9e1892aa91 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1108,6 +1108,44 @@ static int uclogic_params_parse_ugee_v2_desc(const __u8 *str_desc, return 0; } +/** + * uclogic_params_ugee_v2_init_frame_buttons() - initialize a UGEE v2 frame with + * buttons. + * @p: Parameters to fill in, cannot be NULL. + * @desc_params: Device description params list. + * @desc_params_size: Size of the description params list. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_params_ugee_v2_init_frame_buttons(struct uclogic_params *p, + const s32 *desc_params, + size_t desc_params_size) +{ + __u8 *rdesc_frame = NULL; + int rc = 0; + + if (!p || desc_params_size != UCLOGIC_RDESC_PH_ID_NUM) + return -EINVAL; + + rdesc_frame = uclogic_rdesc_template_apply( + uclogic_rdesc_ugee_v2_frame_btn_template_arr, + uclogic_rdesc_ugee_v2_frame_btn_template_size, + desc_params, UCLOGIC_RDESC_PH_ID_NUM); + if (!rdesc_frame) + return -ENOMEM; + + 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) + return rc; + + return 0; +} + /** * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by * discovering their parameters. @@ -1136,7 +1174,6 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, 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]; __u8 magic_arr[] = { 0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -1205,20 +1242,8 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, 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); + rc = uclogic_params_ugee_v2_init_frame_buttons(&p, desc_params, + ARRAY_SIZE(desc_params)); if (rc) { uclogic_params_init_invalid(&p); goto output; From patchwork Sun Jul 17 14:43:30 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: 591421 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 55CABC433EF for ; Sun, 17 Jul 2022 14:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbiGQOnp (ORCPT ); Sun, 17 Jul 2022 10:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbiGQOnn (ORCPT ); Sun, 17 Jul 2022 10:43:43 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6905B33D; Sun, 17 Jul 2022 07:43:42 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so5902114wmb.3; Sun, 17 Jul 2022 07:43:41 -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=OSvkv9mhPoR5bDUGa6yltbm4LgVU497Un5RAIEDmaBw=; b=oy7FABt0ZqspuQXxkbAsUwgoeiie8f8pR7wMaLrPnq6NtF7p7imjWOW2YCCmL6ht2g rR9KQ7+jaWsLzsbNTkjj0fLCiGF06yv1+/q19C8t9sSu1D0WLJ+duyXdnRTIM29TKIqG LPIVql4yVmjIFu93dsD3fJp7ItEpzwNxUUySZdtsrUgheUX6mNUyZ23lz75qD0xzpGTw ncPXAdIzhdVHTp4dFPZkYhBzrBaZZfgJLveZ1lYGAHKViawhBE/YHCAzu0K8hQAga0fy OmyhSJ90GurcN5Ext69MICDhg4BvUN+d8DGKMNUHP688pYk8b0TUgBka0Kyh0b50wRoi VeEw== 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=OSvkv9mhPoR5bDUGa6yltbm4LgVU497Un5RAIEDmaBw=; b=YeYKJ47ZthoTti/RPTUdm6rMyOUBHVj5nyw+WuKCNiJQDrP84sdSZSicPj8dECRvQL jr3TeNPlOWVpPBBEta0GGqiaRC91J7OrjlfWnLV0RSpHdiqLEQEQwD70tLgFoZl533ez JNb4PZMUkx7tD4Zwr+xh6t+YI13dwIVsgJszdXkbx57X789DcHauXaETwhzLiLw8AiCw 2f1Px04IwXIFZ3Tdc7YDbvGg+wwjhGgUpVLCAF7lPPEY+ssyKwl6gxakP25CEauDF68U JqAuqFzWwoKuesfeQt18P7m5Wc1GHePTPP3tzR/QjXYFyedq8P0LEipu3TtgpIK4EhgI 1aNA== X-Gm-Message-State: AJIora/xMSMtcZ4mTHrhcTmSPFeijfFlRlE5JVmayDkC82WKx421AIof iWDeZRtcKIwMtpo1yX08bE6+/pvPZ+hq6g== X-Google-Smtp-Source: AGRyM1uOdrJrs8kaUoH/MV8NqPqO7Xf1puX0NKT7Sju8oEEtsVqmhUeW2DPGbweTVY+cvk1r5zMLqg== X-Received: by 2002:a7b:cb82:0:b0:39e:f9cf:12b7 with SMTP id m2-20020a7bcb82000000b0039ef9cf12b7mr29052758wmi.135.1658069020473; Sun, 17 Jul 2022 07:43:40 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:40 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 4/7] HID: uclogic: Parse the UGEE v2 frame type Date: Sun, 17 Jul 2022 16:43:30 +0200 Message-Id: <20220717144333.251190-5-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The string descriptor returned by UGEE v2 devices contains a byte indicating the device frame type. The values discovered so far are: - 0: Frame with buttons, present in the XP-PEN Deco L. - 1: Frame with buttons and dial, present in the PARBLO A610 PRO. - 2: Frame with buttons and a mouse, shaped as a dial + touchpad. Present in the XP-PEN Deco Pro S. Parse the frame type and add KUnit tests. Tested-by: Jouke Witteveen Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params-test.c | 35 ++++++++++++++++++++++++++- drivers/hid/hid-uclogic-params.c | 19 ++++++++++++--- drivers/hid/hid-uclogic-params.h | 10 ++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-uclogic-params-test.c b/drivers/hid/hid-uclogic-params-test.c index 9f043f2ab387..57ef5d3e4b74 100644 --- a/drivers/hid/hid-uclogic-params-test.c +++ b/drivers/hid/hid-uclogic-params-test.c @@ -7,6 +7,7 @@ */ #include +#include "./hid-uclogic-params.h" #include "./hid-uclogic-rdesc.h" #define MAX_STR_DESC_SIZE 14 @@ -17,6 +18,7 @@ struct uclogic_parse_ugee_v2_desc_case { const __u8 str_desc[MAX_STR_DESC_SIZE]; size_t str_desc_size; const s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; + enum uclogic_params_frame_type frame_type; }; static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] = { @@ -26,6 +28,7 @@ static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] .str_desc = {}, .str_desc_size = 0, .desc_params = {}, + .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS, }, { .name = "resolution_with_value_0", @@ -48,6 +51,7 @@ static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08, }, + .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS, }, /* XP-PEN Deco L str_desc: Frame with 8 buttons */ { @@ -71,6 +75,7 @@ static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08, }, + .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS, }, /* PARBLO A610 PRO str_desc: Frame with 9 buttons and dial */ { @@ -94,6 +99,31 @@ static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x09, }, + .frame_type = UCLOGIC_PARAMS_FRAME_DIAL, + }, + /* XP-PEN Deco Pro S str_desc: Frame with 8 buttons and mouse */ + { + .name = "frame_type_mouse", + .res = 0, + .str_desc = { + 0x0E, 0x03, + 0xC8, 0xB3, + 0x34, 0x65, + 0x08, + 0x02, + 0xFF, 0x1F, + 0xD8, 0x13, + }, + .str_desc_size = 12, + .desc_params = { + [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB3C8, + [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2363, + [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x6534, + [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x13EC, + [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF, + [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08, + }, + .frame_type = UCLOGIC_PARAMS_FRAME_MOUSE, }, }; @@ -110,12 +140,14 @@ static void uclogic_parse_ugee_v2_desc_test(struct kunit *test) { int res; s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; + enum uclogic_params_frame_type frame_type; const struct uclogic_parse_ugee_v2_desc_case *params = test->param_value; res = uclogic_params_parse_ugee_v2_desc(params->str_desc, params->str_desc_size, desc_params, - ARRAY_SIZE(desc_params)); + ARRAY_SIZE(desc_params), + &frame_type); KUNIT_ASSERT_EQ(test, res, params->res); if (res) @@ -139,6 +171,7 @@ static void uclogic_parse_ugee_v2_desc_test(struct kunit *test) KUNIT_EXPECT_EQ(test, params->desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM], desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM]); + KUNIT_EXPECT_EQ(test, params->frame_type, frame_type); } static struct kunit_case hid_uclogic_params_test_cases[] = { diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 7b9e1892aa91..b232125f6972 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1060,6 +1060,7 @@ static int uclogic_probe_interface(struct hid_device *hdev, u8 *magic_arr, * @str_desc_size: Size of the string descriptor. * @desc_params: Output description params list. * @desc_params_size: Size of the output description params list. + * @frame_type: Output frame type. * * Returns: * Zero, if successful. A negative errno code on error. @@ -1067,7 +1068,8 @@ static int uclogic_probe_interface(struct hid_device *hdev, u8 *magic_arr, static int uclogic_params_parse_ugee_v2_desc(const __u8 *str_desc, size_t str_desc_size, s32 *desc_params, - size_t desc_params_size) + size_t desc_params_size, + enum uclogic_params_frame_type *frame_type) { s32 pen_x_lm, pen_y_lm; s32 pen_x_pm, pen_y_pm; @@ -1087,6 +1089,7 @@ static int uclogic_params_parse_ugee_v2_desc(const __u8 *str_desc, pen_x_lm = get_unaligned_le16(str_desc + 2); pen_y_lm = get_unaligned_le16(str_desc + 4); frame_num_buttons = str_desc[6]; + *frame_type = str_desc[7]; pen_pressure_lm = get_unaligned_le16(str_desc + 8); resolution = get_unaligned_le16(str_desc + 10); @@ -1175,6 +1178,7 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, __u8 *str_desc = NULL; __u8 *rdesc_pen = NULL; s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM]; + enum uclogic_params_frame_type frame_type; __u8 magic_arr[] = { 0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -1218,7 +1222,8 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, rc = uclogic_params_parse_ugee_v2_desc(str_desc, str_desc_len, desc_params, - ARRAY_SIZE(desc_params)); + ARRAY_SIZE(desc_params), + &frame_type); if (rc) goto cleanup; @@ -1242,8 +1247,14 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID; /* Initialize the frame interface */ - rc = uclogic_params_ugee_v2_init_frame_buttons(&p, desc_params, - ARRAY_SIZE(desc_params)); + switch (frame_type) { + case UCLOGIC_PARAMS_FRAME_BUTTONS: + default: + rc = uclogic_params_ugee_v2_init_frame_buttons(&p, desc_params, + ARRAY_SIZE(desc_params)); + break; + } + if (rc) { uclogic_params_init_invalid(&p); goto output; diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index 5bef8daaa607..a97477c02ff8 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -29,6 +29,16 @@ enum uclogic_params_pen_inrange { UCLOGIC_PARAMS_PEN_INRANGE_NONE, }; +/* Types of frames */ +enum uclogic_params_frame_type { + /* Frame with buttons */ + UCLOGIC_PARAMS_FRAME_BUTTONS = 0, + /* Frame with buttons and a dial */ + UCLOGIC_PARAMS_FRAME_DIAL, + /* Frame with buttons and a mouse (shaped as a dial + touchpad) */ + UCLOGIC_PARAMS_FRAME_MOUSE, +}; + /* * Pen report's subreport data. */ From patchwork Sun Jul 17 14:43:31 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: 591555 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 443EAC43334 for ; Sun, 17 Jul 2022 14:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233009AbiGQOoC (ORCPT ); Sun, 17 Jul 2022 10:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232704AbiGQOnp (ORCPT ); Sun, 17 Jul 2022 10:43:45 -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 D722DD9B; Sun, 17 Jul 2022 07:43:42 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id bu1so13522151wrb.9; Sun, 17 Jul 2022 07:43:42 -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=OMwhz1M1zPryVflcNS8Rn/GSnUJtV+dvUFo/LQneMlo=; b=EjKAWI2jcjHarcEnwNRhqN284M9RnO818R3l+pNYYRLS206P81sRlqpL2gNzOKlFB4 fV2QQc/wtIO9IeHDWD/tqH1hirILcTqz+K4xrBdWWWIjzv5R+82fCOp8sAgJZJfVMWOR AUPelsuApa8AEDRqXjf0b4jFRl3i/hytVwnFRUaAvsfA7tb7+bFeVI+FtZDS/RmFMzMY QlpyQa6LDVJAs9s45bIYSSwWrjRxOyci3lxeNPLTN682QvWhgz50YVhpusbXaYa9BOkW tX6arJo1ML0mA8uTUWS3Uo6qrgr5vP9uoQDouUTyJ13AjaZSFmXOn4SQMnENiOTvvtnE rKJQ== 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=OMwhz1M1zPryVflcNS8Rn/GSnUJtV+dvUFo/LQneMlo=; b=3G4Ym4PUVzP0kIKGznwiQ6xE9i3rko94aG/SrnKJs4fMCoxYVI3tBX+Frv32Ku30h+ caEV4E/1WQUPq1rT4gGRBzvqIGJf156u14kaXEGp5s2wKJ2tHLN+/QjsIRCT23hPxIiI hcyLRipIVLH5//nsRmjiAtOqeaqMvTPFZVx+5DhOseq/2IBNJ6okC0/XUnWjJi9pprCq WErT5B/5DwuVuEw4/0c5Xag+xpj5u9LlhehccbgaUoI8KqI1p48nxYwKyWSNAPqFHLhZ wRRN5WDiUquMJ6QakjNzY+FoLtsRi1aJp99I9AppoM7V63okbzjVZj6gRwSaZQpkqKsM X99Q== X-Gm-Message-State: AJIora9a8AmaBYDyxm4MUd+cVLkdbDpSz6MOH7Ppeb3c9a66+zqTcHG7 EewORAHtbVqpDATbrpVkJzA= X-Google-Smtp-Source: AGRyM1ufGF/tZUJDe702VxyCMSYZ+wgLXDXaugkwo+5JSGnF+fORpm/ogyow8VvdChrVYJFrbx9raQ== X-Received: by 2002:a5d:64a4:0:b0:21d:be80:de06 with SMTP id m4-20020a5d64a4000000b0021dbe80de06mr17245544wrp.107.1658069021326; Sun, 17 Jul 2022 07:43:41 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:41 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 5/7] HID: uclogic: Add support for UGEE v2 dial frames Date: Sun, 17 Jul 2022 16:43:31 +0200 Message-Id: <20220717144333.251190-6-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add the required HID descriptors and the initialization function for UGEE v2 frames with a bitmap dial. Tested-by: Jouke Witteveen Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params.c | 44 ++++++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 40 +++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 4 +++ 3 files changed, 88 insertions(+) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index b232125f6972..8ac7caeda535 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1149,6 +1149,45 @@ static int uclogic_params_ugee_v2_init_frame_buttons(struct uclogic_params *p, return 0; } +/** + * uclogic_params_ugee_v2_init_frame_dial() - initialize a UGEE v2 frame with a + * bitmap dial. + * @p: Parameters to fill in, cannot be NULL. + * @desc_params: Device description params list. + * @desc_params_size: Size of the description params list. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_params_ugee_v2_init_frame_dial(struct uclogic_params *p, + const s32 *desc_params, + size_t desc_params_size) +{ + __u8 *rdesc_frame = NULL; + int rc = 0; + + if (!p || desc_params_size != UCLOGIC_RDESC_PH_ID_NUM) + return -EINVAL; + + rdesc_frame = uclogic_rdesc_template_apply( + uclogic_rdesc_ugee_v2_frame_dial_template_arr, + uclogic_rdesc_ugee_v2_frame_dial_template_size, + desc_params, UCLOGIC_RDESC_PH_ID_NUM); + if (!rdesc_frame) + return -ENOMEM; + + rc = uclogic_params_frame_init_with_desc(&p->frame_list[0], + rdesc_frame, + uclogic_rdesc_ugee_v2_frame_dial_template_size, + UCLOGIC_RDESC_V1_FRAME_ID); + kfree(rdesc_frame); + if (rc) + return rc; + + p->frame_list[0].bitmap_dial_byte = 7; + return 0; +} + /** * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by * discovering their parameters. @@ -1248,6 +1287,11 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, /* Initialize the frame interface */ switch (frame_type) { + case UCLOGIC_PARAMS_FRAME_DIAL: + case UCLOGIC_PARAMS_FRAME_MOUSE: + rc = uclogic_params_ugee_v2_init_frame_dial(&p, desc_params, + ARRAY_SIZE(desc_params)); + break; case UCLOGIC_PARAMS_FRAME_BUTTONS: default: rc = uclogic_params_ugee_v2_init_frame_buttons(&p, desc_params, diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 3d68e8b0784d..22429df693fc 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -961,6 +961,46 @@ const __u8 uclogic_rdesc_ugee_v2_frame_btn_template_arr[] = { const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size = sizeof(uclogic_rdesc_ugee_v2_frame_btn_template_arr); +/* Fixed report descriptor template for UGEE v2 frame reports (dial) */ +const __u8 uclogic_rdesc_ugee_v2_frame_dial_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, 0x06, /* Report Count (6), */ + 0x81, 0x01, /* Input (Constant), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x03, /* Report Count (3), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x38, /* Usage (Wheel), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0xFF, /* Logical Minimum (-1), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x81, 0x06, /* Input (Variable, Relative), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_ugee_v2_frame_dial_template_size = + sizeof(uclogic_rdesc_ugee_v2_frame_dial_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 86e64a9ee6bd..1a2d658bad3a 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -169,6 +169,10 @@ extern const size_t uclogic_rdesc_ugee_v2_pen_template_size; 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 template for UGEE v2 frame reports (dial) */ +extern const __u8 uclogic_rdesc_ugee_v2_frame_dial_template_arr[]; +extern const size_t uclogic_rdesc_ugee_v2_frame_dial_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; From patchwork Sun Jul 17 14:43:32 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: 591420 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 0FDC9CCA47B for ; Sun, 17 Jul 2022 14:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233073AbiGQOoD (ORCPT ); Sun, 17 Jul 2022 10:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232458AbiGQOnp (ORCPT ); Sun, 17 Jul 2022 10:43:45 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8215F68; Sun, 17 Jul 2022 07:43:43 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id n12so691887wrc.8; Sun, 17 Jul 2022 07:43:43 -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=PQ1NQYAY40VdIfaKD7aTOcgtuEul8hn8SxDvqqcPU2M=; b=ikvvcQRqGWvJ/WJZVtSdtagXjZ5UVt03LXCmCXnoP7UIGyf5J3LiJZy39cN9rHvfxI oc1UTMHxxsd3hHU/K2vLpNVRPBTc4uxEGsUVGjjSsVT0U7uT3zlc8EYfZW6uybfkD7Wh J6i6ILslh0EbqxI1PEBJrpxnR0zgqhvQAGIIMVl2pYUFOTvjnlDRjkl0OqhQdjxIPovQ eqaBkqsVA3OyPwdjFZV+9OPwM6/CXzQIHMbXPbZJ3iOh1ZgIJamZb6vWhl2OnnN6uUH/ dBoVHnGoCnOa4CPBjS90Fu4KKiVWE0ynNdS5svDFplq+LzsWjx86XIYfx1GlVzl2lk7W Eikw== 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=PQ1NQYAY40VdIfaKD7aTOcgtuEul8hn8SxDvqqcPU2M=; b=w/nL2i0rw241p9lvUHnh0sDeUixCDT5zJXS+IdWrsUrGjvzs7lyE5W0rPClcz2i5eG aDpzXsFUuzs5YLC6Lx1KlIVDPr3JgyhLbgg6jYbO4GExuutQzheqxAFJCd4M5sr3IEBj m0Y7+zyObCokL5NpmN2xk4X/u9K+ox3HtrSyytIT7APMC7vyNiOguIJoUbSc4ACpqJdV Hxe5S2Lr8ItEoNGfr97cH/L59wPwJecKsJfszkW338iU0WKUq36R5zHxDOslA8QBwfdE S+/diYgI9MOMzYGNc+X3bTK2Gz5S9R6zVxlwKXCQkuXdmXKZwqCMVl0UEhzuZmuy7Dc9 Wk4Q== X-Gm-Message-State: AJIora8msBGJ/klBPaY2qwtpSl4wNUwiKDMS/Hn4+Y7AOMeyS7cLOdZb AMnbB1Bv0GCbsBuKIwfDpjE= X-Google-Smtp-Source: AGRyM1sJWV+5Fv+yrbtT0yaWM1aV3e3j3qs2ieRT/En8K3w2nce7D2xDTMFvOqGf9BoudFPwrx4ZwQ== X-Received: by 2002:adf:f847:0:b0:21d:6c3b:ecbf with SMTP id d7-20020adff847000000b0021d6c3becbfmr19584148wrq.423.1658069022140; Sun, 17 Jul 2022 07:43:42 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:41 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 6/7] HID: uclogic: Add support for UGEE v2 mouse frames Date: Sun, 17 Jul 2022 16:43:32 +0200 Message-Id: <20220717144333.251190-7-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add the required HID descriptors and the initialization function for UGEE v2 frames with a mouse in the frame. Tested-by: Jouke Witteveen Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params.c | 31 +++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 34 ++++++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 4 ++++ 3 files changed, 69 insertions(+) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 8ac7caeda535..f25c483b794b 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1188,6 +1188,31 @@ static int uclogic_params_ugee_v2_init_frame_dial(struct uclogic_params *p, return 0; } +/** + * uclogic_params_ugee_v2_init_frame_mouse() - initialize a UGEE v2 frame with a + * mouse. + * @p: Parameters to fill in, cannot be NULL. + * + * Returns: + * Zero, if successful. A negative errno code on error. + */ +static int uclogic_params_ugee_v2_init_frame_mouse(struct uclogic_params *p) +{ + int rc = 0; + + if (!p) + return -EINVAL; + + rc = uclogic_params_frame_init_with_desc(&p->frame_list[1], + uclogic_rdesc_ugee_v2_frame_mouse_template_arr, + uclogic_rdesc_ugee_v2_frame_dial_template_size, + UCLOGIC_RDESC_V1_FRAME_ID); + if (rc) + return rc; + + return 0; +} + /** * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by * discovering their parameters. @@ -1231,6 +1256,12 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, iface = to_usb_interface(hdev->dev.parent); bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + + if (bInterfaceNumber == 0) { + uclogic_params_ugee_v2_init_frame_mouse(&p); + goto output; + } + if (bInterfaceNumber != 2) { uclogic_params_init_invalid(&p); goto output; diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 22429df693fc..fb9ca69f72c2 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -1001,6 +1001,40 @@ const __u8 uclogic_rdesc_ugee_v2_frame_dial_template_arr[] = { const size_t uclogic_rdesc_ugee_v2_frame_dial_template_size = sizeof(uclogic_rdesc_ugee_v2_frame_dial_template_arr); +/* Fixed report descriptor template for UGEE v2 frame reports (mouse) */ +const __u8 uclogic_rdesc_ugee_v2_frame_mouse_template_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x02, /* Usage (Mouse), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, 0x01, /* Report ID (1), */ + 0x05, 0x01, /* Usage Page (Pointer), */ + 0xA0, /* Collection (Physical), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x02, /* Report Count (2), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x19, 0x01, /* Usage Minimum (01h), */ + 0x29, 0x02, /* Usage Maximum (02h), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x06, /* Report Count (6), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x01, /* Usage Page (Generic Desktop), */ + 0x09, 0x30, /* Usage (X), */ + 0x09, 0x31, /* Usage (Y), */ + 0x75, 0x10, /* Report Size (16), */ + 0x95, 0x02, /* Report Count (2), */ + 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ + 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */ + 0x81, 0x06, /* Input (Variable, Relative), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_ugee_v2_frame_mouse_template_size = + sizeof(uclogic_rdesc_ugee_v2_frame_mouse_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 1a2d658bad3a..0502a0656496 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -173,6 +173,10 @@ extern const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size; extern const __u8 uclogic_rdesc_ugee_v2_frame_dial_template_arr[]; extern const size_t uclogic_rdesc_ugee_v2_frame_dial_template_size; +/* Fixed report descriptor template for UGEE v2 frame reports (mouse) */ +extern const __u8 uclogic_rdesc_ugee_v2_frame_mouse_template_arr[]; +extern const size_t uclogic_rdesc_ugee_v2_frame_mouse_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; From patchwork Sun Jul 17 14:43:33 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: 591554 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 1A9F5C43334 for ; Sun, 17 Jul 2022 14:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232867AbiGQOoG (ORCPT ); Sun, 17 Jul 2022 10:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbiGQOnt (ORCPT ); Sun, 17 Jul 2022 10:43:49 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D3F32DEF; Sun, 17 Jul 2022 07:43:44 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id f2so13515378wrr.6; Sun, 17 Jul 2022 07:43:44 -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=LM0lgQs2BA1X3p/kw499UJ/iLAvQnGCmtoBS9FDHPxY=; b=cFM43fkyj8iTvUYNU8VmF4oJsJWrobp09MEUk5vA8lZI/hzJP0m5zcufHDk2MbRt4z b/M84mcuJc27iitT4XDubfvPSApPZ8dm7Fn7h9LufZZDJcR+aAZ8AXENyqpZ5hb79QAL 5fZ6OGXBgTBdqowdrFvRJRXo6QDrfS8VAbFzyzxbI7+u2h2eicPoXTb/ViWEM6KACUho tyqbI7acXfpihqgODtoT5zipuGCrZzhESRRpM8SyTi8+4C375BGqzIykLHK0c5qHmGH+ yeAxQ21Rnusr8K0a5yIEOOogCXw0ORyI1Vgncq+CulYDyslA76awYn/yvXBAYsm6CYWk i62A== 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=LM0lgQs2BA1X3p/kw499UJ/iLAvQnGCmtoBS9FDHPxY=; b=62o4Fyjk8Nbkv4wk0li6IWp4IaeL7XcMSxushyguJEFqwkp54k7AoVtySS3sW0mKsX l/khR5A+HA8/bfS+B36n2ByAuqwwmQLTKC47P35VkJ4pbBPbwDY7YH0MiMj6+KC2Oopb TxEdKRwMwF+WwpJu0FHvX9KCSKElGdmfFaEn/+tzxSsI7R2+GrZoqO7WvKHLN9PN6PVY uEwT45yz/bgYdyFBm7MTR/jvvmrapl+8wZOu/yKglJB0habgpNmVN1fgsny5Ubiye33J HJ97ZS/SPWUMrCdTVfk/IFEsyGqr+KJjAGbuLvthFOWKRn7PFYDncc8XcVEbGqQyiJgA TZLg== X-Gm-Message-State: AJIora+bMCK0BGntMmMnVC2EVRLCiSOocqwVXFTyPwi8n+Jv+NAxPwRA 4d7RjYI8cARGwm0z4fRMT94nBiGh3yBMFw== X-Google-Smtp-Source: AGRyM1ty2yw20Y/EIbS0zt0GrcOpmgcAT0co7Lbx8vjUa7EFqWpUV5YQtnnvvDFIHtSGjUG7QY7Ylw== X-Received: by 2002:adf:f1d1:0:b0:21d:7f88:d638 with SMTP id z17-20020adff1d1000000b0021d7f88d638mr19545964wro.586.1658069022975; Sun, 17 Jul 2022 07:43:42 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.185]) by smtp.gmail.com with ESMTPSA id h8-20020adff4c8000000b0021d887f9468sm8432001wrp.25.2022.07.17.07.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 07:43:42 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, j.witteveen@gmail.com, stefanberzl@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= Subject: [PATCH v2 7/7] HID: uclogic: Add support for XP-PEN Deco Pro S Date: Sun, 17 Jul 2022 16:43:33 +0200 Message-Id: <20220717144333.251190-8-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717144333.251190-1-jose.exposito89@gmail.com> References: <20220717144333.251190-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 Pro S is a UGEE v2 device with a frame with 8 buttons, a bitmap dial and a mouse. Its pen has 2 buttons, supports tilt and pressure. All the pieces to support it are already in place. Add its ID in order to support the device. The required Wireshark traces were captured by Jouke Witteveen. For more information check [1]. Link: https://gitlab.freedesktop.org/libinput/libinput/-/issues/738 [1] Tested-by: Jouke Witteveen 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 | 2 ++ 3 files changed, 5 insertions(+) diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 139910034c17..ee6d27a5dd1c 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -1279,6 +1279,7 @@ #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_DECO_PRO_S 0x0909 #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 47a17375c7fc..6fcdb141acec 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -523,6 +523,8 @@ static const struct hid_device_id uclogic_devices[] = { 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_DECO_PRO_S) }, { 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 f25c483b794b..2407e927d1bf 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1583,6 +1583,8 @@ int uclogic_params_init(struct uclogic_params *params, break; case VID_PID(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L): + case VID_PID(USB_VENDOR_ID_UGEE, + USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_PRO_S): rc = uclogic_params_ugee_v2_init(&p, hdev); if (rc != 0) goto cleanup;