From patchwork Sat Oct 29 16:12:39 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: 12742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1424413wru; Sat, 29 Oct 2022 09:44:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KKk4ce/LWgaZocAGibD/HNWzkvnSH0OC4tbqjFr2wy1a1pnRk5iIagOfBZgzeQ4rCuiqd X-Received: by 2002:a17:907:16a7:b0:79e:a72c:d00e with SMTP id hc39-20020a17090716a700b0079ea72cd00emr4506243ejc.214.1667061872304; Sat, 29 Oct 2022 09:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667061872; cv=none; d=google.com; s=arc-20160816; b=pvrsCPFxHcJUPr+WMWX6zppPMkgpJiTsj3oW3oVDdexXydmx44Y2JX30dLhWWtZLtS hFT1vY0A3Mrfb1x1ql5HFEeGUvILLauC90YOmRj3MY3ywFqNyCppkBpvKq4D2QPLgbLf Lhs1Clqq3E5QQo7Isr3fEpDCATObKKbcmqzl/xNxa3wPCNgU2pN9OgOthkakYTPsqfHY sP2ATDed9I3wvVubzSASBK9zd7wfiZ/2vulbqET+ZiRls4xFOLhPXAHOblZaGFSnUVjg Rv8uaQjAMW168U5C5PLkWJt7bRnTjriMkewCdGuKmHPS6ixU8FI6w4H/NMYlS06z6SY6 lQ5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YVq/27+BODVwXDvbhB9aF4lOvnY7b7DgJThrg3Kmek4=; b=V7rk8BlEqiYfLRe+NJ0GWYbtMCYVQRNpDn3uvjiqy7A/jsc5AdeTUyK7JYxsB2DKyS cXP7Q1diYX32ORwg7FNJCBOr7v+GjVHBBaiRG0MySXpM3k3dxMgcCCHPunS5/a8eVSha mMlMZ89bqSG11qiZhhrd/ofoxt002njzz/HjLrGLJYN+PPcIVwP99ZgurmuLleiifuwj TgBptOXcUoY4KKXjDGgPRAueeZVzvUAw5kH4J7dRhVw9lVhxM7eyM6EWE9BPs4DwDGyk EfM3d5sr6tBEDBOQxrDC38su12rFtsd6LbaFA4BmluMB8YDGZ0XKKrHUhRA0HX3hC6HZ BOuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IIe0TxqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j16-20020a05640211d000b004621e2c473dsi2782609edw.354.2022.10.29.09.44.08; Sat, 29 Oct 2022 09:44:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IIe0TxqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbiJ2QMw (ORCPT + 99 others); Sat, 29 Oct 2022 12:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbiJ2QMs (ORCPT ); Sat, 29 Oct 2022 12:12:48 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0AF3FEE9; Sat, 29 Oct 2022 09:12:46 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso8290631wma.1; Sat, 29 Oct 2022 09:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YVq/27+BODVwXDvbhB9aF4lOvnY7b7DgJThrg3Kmek4=; b=IIe0TxqD14AXA+JM8LlADgyM6x3tDQlkiVXhQD5xunyEi0NLwjaeJBecup4qovTSCM IQ77GaNPAlgTTVB0CsEH0h90yzy93Sti+mIindlAB5uBewRQFIBcYiaxizDPhAbVpYSM 8aatB/r9Cu17yK/HZBteiA/KxLSLlGtZew8pnp79LVpfsXLvIIAV4LVZnHgEhNnub/LO fV45GTf6FpvUIrJ2vLy0zGuTUsXnLMVMf8q6AlO4wtEQPzeaDFOQhb18NEkP3RLlayI9 29i7VdHxqC5TWvYmsSwqSwHRe5dtg1kP4l4IwV3IvNZaNle+lpn5F95Cv2G+TuXeZ49H UD9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YVq/27+BODVwXDvbhB9aF4lOvnY7b7DgJThrg3Kmek4=; b=Av5A9R4yiybZFjRW6dr9jfpomhmJ4U1xVKuvay+8JVGINjdxVbtQXM736e6SzkJIMa vQ0jj2WFXGTREHcpxmeKVSuiYSjj3xIIM/vFV54BB6FgWbKDjVtzdxk77W43hzjgwBeY p6F/iAulaRoIdc+GCSNO4OpAUUrSpOeH0VEiJlWR1Zdr2QFCJoRp85gqk0dpWQdFOJkn L2AoCccP2CjD2ZYKxR0fKx87WqBWnCCoOguHUcTGtJk7jCFZt7zbApyTiCoaao1GQ0bO 0vQM7cBeYQrNhkIMkKgHkgNLPWU0sie0BVvbY91Oedyx2cr6kZ8kmoWd5LEj/MjNk+D8 M4aA== X-Gm-Message-State: ACrzQf1/eGw4zQz3q2LbL/8MZJD25J+Dw2hgXSasaX1LL07Tggs+clSl Mm/rq02p9KB3QYzn3JP/msU= X-Received: by 2002:a05:600c:198a:b0:3c6:f6b4:68d5 with SMTP id t10-20020a05600c198a00b003c6f6b468d5mr2745683wmq.14.1667059965123; Sat, 29 Oct 2022 09:12:45 -0700 (PDT) Received: from localhost.localdomain ([94.73.35.109]) by smtp.gmail.com with ESMTPSA id f28-20020a5d58fc000000b0022efc4322a9sm1858471wrd.10.2022.10.29.09.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 09:12:44 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, pobrn@protonmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= , Mia Kanashi Subject: [PATCH v3 1/2] HID: input: do not query XP-PEN Deco LW battery Date: Sat, 29 Oct 2022 18:12:39 +0200 Message-Id: <20221029161240.15548-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221029161240.15548-1-jose.exposito89@gmail.com> References: <20221029161240.15548-1-jose.exposito89@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748041069830150494?= X-GMAIL-MSGID: =?utf-8?q?1748041069830150494?= The XP-PEN Deco LW drawing tablet can be connected by USB cable or using a USB Bluetooth dongle. When it is connected using the dongle, there might be a small delay until the tablet is paired with the dongle. Fetching the device battery during this delay results in random battery percentage values. Add a quirk to avoid actively querying the battery percentage and wait for the device to report it on its own. Reported-by: Mia Kanashi Signed-off-by: José Expósito --- drivers/hid/hid-input.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 859aeb07542e..d728a94c642e 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -340,6 +340,7 @@ static enum power_supply_property hidinput_battery_props[] = { #define HID_BATTERY_QUIRK_PERCENT (1 << 0) /* always reports percent */ #define HID_BATTERY_QUIRK_FEATURE (1 << 1) /* ask for feature report */ #define HID_BATTERY_QUIRK_IGNORE (1 << 2) /* completely ignore the battery */ +#define HID_BATTERY_QUIRK_AVOID_QUERY (1 << 3) /* do not query the battery */ static const struct hid_device_id hid_battery_quirks[] = { { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, @@ -373,6 +374,8 @@ static const struct hid_device_id hid_battery_quirks[] = { HID_BATTERY_QUIRK_IGNORE }, { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ASUS_UX550VE_TOUCHSCREEN), HID_BATTERY_QUIRK_IGNORE }, + { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L), + HID_BATTERY_QUIRK_AVOID_QUERY }, { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, I2C_DEVICE_ID_HP_ENVY_X360_15), HID_BATTERY_QUIRK_IGNORE }, { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, I2C_DEVICE_ID_HP_ENVY_X360_15T_DR100), @@ -554,6 +557,9 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, dev->battery_avoid_query = report_type == HID_INPUT_REPORT && field->physical == HID_DG_STYLUS; + if (quirks & HID_BATTERY_QUIRK_AVOID_QUERY) + dev->battery_avoid_query = true; + dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg); if (IS_ERR(dev->battery)) { error = PTR_ERR(dev->battery); From patchwork Sat Oct 29 16:12:40 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: 12741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1423241wru; Sat, 29 Oct 2022 09:40:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xpYIUlGIq0ewiI+ogDEVE3zHMcG/RTstyvtZAXZnDW8UV23hJKlvZ6vMzjyWEk/Pq14lB X-Received: by 2002:a17:907:1623:b0:78d:9e8b:171d with SMTP id hb35-20020a170907162300b0078d9e8b171dmr4571044ejc.309.1667061649065; Sat, 29 Oct 2022 09:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667061649; cv=none; d=google.com; s=arc-20160816; b=AFo76ox0iHSV38agETi0E/1d2eHgg0ZKI/3TGDornRMTJGFWgX9DO14VFjOxuDRmsg 2f9mBemvTM0HHuUlMQwkiM3rVcAMU/fINavA/ikUMBIz2+US0apQOK7ZlMmfPcNxTTBa /XeFNxwF/FTIHWON9ETbnOgFkKNWf+yjj1w3OAObDT6zyT7tg/qeic/O4dnCkYA3a+pH DUfAuCiiYhOclTfjRr9KUsaCa99s8qv5jVG11axqSLqVx8tEY8lcWKblG+b4VUZm8VWq 6wcrz9B1vGvWO96VEmhcJq0/KSL/iagaudXHTtLOuzT/IUIV9PsYmsmPZJY3tv+aBTBG f//Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TSFlkVa4uZT7WAqGVAQDW7nXJPJ44iMTkg4mDYwcPRo=; b=npoHQZnXLSXcFMD/+fz/M0VP4Dy+00n+XHFAsEiZsbcDuhlHzXUaXJZmAe4gFr+ulM KpLx1/ZvyrRGYTn8Sd4YYlR8NQuG3owfzlQ7JAVBE/9b07fmMmx5REkn0hajydeo57av 97txJuANe/nehIKQVAypCjZoAX5N9YgAoDBsOdTMX4mCPBSEiDy9hTpFk5Gh7XjA/pv2 7WzZsdJgSbii5+ww3KQwvyVGp92pFyhFQgidXPH8lA0rRTB/PRXhw9132UJYc4z0f5eb 58f3XTQ6FI6Bo170Xj7dmMEd/eo8E+YvySyvzak8iZnDsPzk5HDbiYnm8ANh8V1rVVZO E0rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=H1xNPSkd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my15-20020a1709065a4f00b00782ff2649a7si1628008ejc.346.2022.10.29.09.40.23; Sat, 29 Oct 2022 09:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=H1xNPSkd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbiJ2QMz (ORCPT + 99 others); Sat, 29 Oct 2022 12:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiJ2QMs (ORCPT ); Sat, 29 Oct 2022 12:12:48 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B0529344; Sat, 29 Oct 2022 09:12:47 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id w14so10230469wru.8; Sat, 29 Oct 2022 09:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TSFlkVa4uZT7WAqGVAQDW7nXJPJ44iMTkg4mDYwcPRo=; b=H1xNPSkdkW2iYMtvuSLbbcM+C5mQyjfFNoPwAq4moBjLFjfe7/57W2HVQBrNRVY7ay D5QDMCbtcwwRxuIjKm7RewsucFm07w2ch1zpukicpxzBLnOde6XqLYDmNrUPiyuTprZ/ j/foTstUCDZqETQkfYTMrkuNuhLO+89BT+QfBX2O9z4PxEKBSkvt25gny9/GyBkA0fkp LEn5C1wzoGtypLS1m1f2xY9124IuEzSDOlUw+/OkBgquuXchosUU5Tn+jjSj4+DzEJXl 4NxemxEg6JlQnoGj6X1HT0WOKWE6C2/EgMFRJJaEEqg0ukl4vrTQ2xnEn9PDStO4/sXS kb5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TSFlkVa4uZT7WAqGVAQDW7nXJPJ44iMTkg4mDYwcPRo=; b=mYR6jQrlCWA3JkJf7hDXwCMGfutDwO61KTw7t58cRwnOdWMxBalHDrFES8wKFcKgvJ FzNml255ar3i2Es90J7cZI9ewWWq4Th67LdyRCrYePfPmMcsmwgvyBxceuk9W/+aRPlo qniIgL+s0GZPmq5Lh4qijAfkPyCbVaqyc/Jk/Js/5Prd8ssTWy6xgHHtJQN7eHwnDN42 I94JIeGFXsmvwZ8ShaPP+3dgvyx7bdY+aTaWq86NmseJ/KCjK6jxk3Q3CE2Xz6k4ouoy XDZrfvVW0hoJj/FKTc/fvrSzcx8jS5Hc6ap7U00fmlNkLWUTQvVEQaqpP1NhV5pT+gUv cl0g== X-Gm-Message-State: ACrzQf0AtyIhGBz7w124bpEmqpOBPvzz6KO383qzGjY0lMvJUYKC7wnH fU79wAg62kaObAPQeBUawk8= X-Received: by 2002:a05:6000:689:b0:236:6c3e:ec88 with SMTP id bo9-20020a056000068900b002366c3eec88mr2660190wrb.346.1667059966309; Sat, 29 Oct 2022 09:12:46 -0700 (PDT) Received: from localhost.localdomain ([94.73.35.109]) by smtp.gmail.com with ESMTPSA id f28-20020a5d58fc000000b0022efc4322a9sm1858471wrd.10.2022.10.29.09.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 09:12:45 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, spbnick@gmail.com, pobrn@protonmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?Sm9z?= =?utf-8?b?w6kgRXhww7NzaXRv?= , Mia Kanashi , Andreas Grosse Subject: [PATCH v3 2/2] HID: uclogic: Add support for XP-PEN Deco LW Date: Sat, 29 Oct 2022 18:12:40 +0200 Message-Id: <20221029161240.15548-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221029161240.15548-1-jose.exposito89@gmail.com> References: <20221029161240.15548-1-jose.exposito89@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748040835814751773?= X-GMAIL-MSGID: =?utf-8?q?1748040835814751773?= The XP-PEN Deco LW is a UGEE v2 device with a frame with 8 buttons. Its pen has 2 buttons, supports tilt and pressure. It can be connected by USB cable or using a USB Bluetooth dongle to use it in wireless mode. When it is connected using the dongle, the device battery is used to power it. Its vendor, product and version are identical to the Deco L. The only difference reported by its firmware is the product name. In order to add support for battery reporting, add a new HID descriptor and a quirk to detect the wireless version of the tablet. Link: https://github.com/DIGImend/digimend-kernel-drivers/issues/635 Tested-by: Mia Kanashi Tested-by: Andreas Grosse Signed-off-by: José Expósito --- drivers/hid/hid-uclogic-params.c | 73 ++++++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 34 +++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 7 +++ 3 files changed, 114 insertions(+) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 34fa991e6267..cd1233d7e253 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -18,6 +18,7 @@ #include "usbhid/usbhid.h" #include "hid-ids.h" #include +#include #include /** @@ -1211,6 +1212,69 @@ static int uclogic_params_ugee_v2_init_frame_mouse(struct uclogic_params *p) return rc; } +/** + * uclogic_params_ugee_v2_has_battery() - check whether a UGEE v2 device has + * battery or not. + * @hdev: The HID device of the tablet interface. + * + * Returns: + * True if the device has battery, false otherwise. + */ +static bool uclogic_params_ugee_v2_has_battery(struct hid_device *hdev) +{ + /* The XP-PEN Deco LW vendor, product and version are identical to the + * Deco L. The only difference reported by their firmware is the product + * name. Add a quirk to support battery reporting on the wireless + * version. + */ + if (hdev->vendor == USB_VENDOR_ID_UGEE && + hdev->product == USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L) { + struct usb_device *udev = hid_to_usb_dev(hdev); + + if (strstarts(udev->product, "Deco LW")) + return true; + } + + return false; +} + +/** + * uclogic_params_ugee_v2_init_battery() - initialize UGEE v2 battery reporting. + * @hdev: The HID device of the tablet interface, cannot be NULL. + * @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_battery(struct hid_device *hdev, + struct uclogic_params *p) +{ + int rc = 0; + + if (!hdev || !p) + return -EINVAL; + + /* Some tablets contain invalid characters in hdev->uniq, throwing a + * "hwmon: '' is not a valid name attribute, please fix" error. + * Use the device vendor and product IDs instead. + */ + snprintf(hdev->uniq, sizeof(hdev->uniq), "%x-%x", hdev->vendor, + hdev->product); + + rc = uclogic_params_frame_init_with_desc(&p->frame_list[1], + uclogic_rdesc_ugee_v2_battery_template_arr, + uclogic_rdesc_ugee_v2_battery_template_size, + UCLOGIC_RDESC_UGEE_V2_BATTERY_ID); + if (rc) + return rc; + + p->frame_list[1].suffix = "Battery"; + p->pen.subreport_list[1].value = 0xf2; + p->pen.subreport_list[1].id = UCLOGIC_RDESC_UGEE_V2_BATTERY_ID; + + return rc; +} + /** * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by * discovering their parameters. @@ -1334,6 +1398,15 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params, if (rc) goto cleanup; + /* Initialize the battery interface*/ + if (uclogic_params_ugee_v2_has_battery(hdev)) { + rc = uclogic_params_ugee_v2_init_battery(hdev, &p); + if (rc) { + hid_err(hdev, "error initializing battery: %d\n", rc); + goto cleanup; + } + } + output: /* Output parameters */ memcpy(params, &p, sizeof(*params)); diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 4bd54c4fb5b0..6524b4b61b25 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -1035,6 +1035,40 @@ const __u8 uclogic_rdesc_ugee_v2_frame_mouse_template_arr[] = { const size_t uclogic_rdesc_ugee_v2_frame_mouse_template_size = sizeof(uclogic_rdesc_ugee_v2_frame_mouse_template_arr); +/* Fixed report descriptor template for UGEE v2 battery reports */ +const __u8 uclogic_rdesc_ugee_v2_battery_template_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x07, /* Usage (Keypad), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, UCLOGIC_RDESC_UGEE_V2_BATTERY_ID, + /* Report ID, */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x84, /* Usage Page (Power Device), */ + 0x05, 0x85, /* Usage Page (Battery System), */ + 0x09, 0x65, /* Usage Page (AbsoluteStateOfCharge), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x26, 0xff, 0x00, /* Logical Maximum (255), */ + 0x81, 0x02, /* Input (Variable), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x09, 0x44, /* Usage Page (Charging), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x07, /* Report Count (7), */ + 0x81, 0x01, /* Input (Constant), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x07, /* Report Count (7), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_ugee_v2_battery_template_size = + sizeof(uclogic_rdesc_ugee_v2_battery_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 0502a0656496..a1f78c07293f 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -161,6 +161,9 @@ 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 +/* Report ID for tweaked UGEE v2 battery reports */ +#define UCLOGIC_RDESC_UGEE_V2_BATTERY_ID 0xba + /* 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; @@ -177,6 +180,10 @@ extern const size_t uclogic_rdesc_ugee_v2_frame_dial_template_size; 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 template for UGEE v2 battery reports */ +extern const __u8 uclogic_rdesc_ugee_v2_battery_template_arr[]; +extern const size_t uclogic_rdesc_ugee_v2_battery_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;