From patchwork Thu Apr 13 18:17:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 673017 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 DB5DEC77B6E for ; Thu, 13 Apr 2023 18:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229959AbjDMSSH (ORCPT ); Thu, 13 Apr 2023 14:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjDMSSB (ORCPT ); Thu, 13 Apr 2023 14:18:01 -0400 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A798A58 for ; Thu, 13 Apr 2023 11:17:49 -0700 (PDT) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-54c0c86a436so418048997b3.6 for ; Thu, 13 Apr 2023 11:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681409869; x=1684001869; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MQczAQBrWdzaEL6ONLzRykYRkgSEoAdka2nj7Q8ZvSc=; b=g4SDWQ+1EG77eUOiWzWcr4zuGk+HceHHndMMEEGB5L2iT+FJhhE26kKkGJtJJg2Fci cG7VpM3azBrzvrI0sL1vZwW6H0LHiJqvkQzcaPkaEDl8k2TypXHnbZz+QIlUymtGeqe/ qtQNe84uRRkI1C2nghuvMlTTzPZB13GcNz2GfzSnNk0wXFSbznv9WLTFSFefXfnf5NCs 5X1uxcAtOl0ReglSWvxR9YFADT/3T+V57cYfuXNHEp+DldhpQVqYZV/IunwX6sEAhjrc 0fVSbQcCmJ5qIBCCPHDstBwWG4JOGjGNb4zTKjnVYZInOaBbP/3OydImBHrPJZUGRCK0 qyQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681409869; x=1684001869; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MQczAQBrWdzaEL6ONLzRykYRkgSEoAdka2nj7Q8ZvSc=; b=QVV2GKCw4xubPTLmx5ueiygyE6uKtPvg9CaNPH7iK9GLRhHSWPsRdvD/YTGXCPLhit 2Ne7DSrFa+zUcHghLeeZfOIlPsKa6i8YKR5js5WEwjd0hh0swtXwkd+H2NG8nLkT4Dp0 TcaB22xoZLKOiFg906ZY8ZQoGZ5uvBa0eX8/UmzpUIacZ+XHCTIFhQPKj/VS9FEBca7/ rkBpp60Km0QgXZNHe8XVMfXh/xMHKDr056MxHK72Lf13Zpcxhm5QTix/Vm5NJTO0RilN Vyjl88kXzlJX+fL8ARgOdfrkp2op0tnYZOTHPfOvjIt8vEGPUdtekZM/nRN8b+J9wrPi rwzg== X-Gm-Message-State: AAQBX9dc6E0+IqPnJqtSKgdC3u66qh+cG2Sg8EDEsPbSRmMPSKiwt9Ms MOsSuhoBdMvO8zzJ+oXXC/HIw6jMPgMepw== X-Google-Smtp-Source: AKy350Z3xEYKSu8abthHPiOec0cjLiEF4TESEWP5jvJO1std0AC4+N9iOJcez8goaywmz/crH6virg== X-Received: by 2002:a0d:ddc9:0:b0:54f:895e:70ff with SMTP id g192-20020a0dddc9000000b0054f895e70ffmr2832745ywe.21.1681409868717; Thu, 13 Apr 2023 11:17:48 -0700 (PDT) Received: from horus.lan (71-34-68-4.ptld.qwest.net. [71.34.68.4]) by smtp.gmail.com with ESMTPSA id l9-20020a817009000000b00545a08184aasm641547ywc.58.2023.04.13.11.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:17:47 -0700 (PDT) From: Jason Gerecke X-Google-Original-From: Jason Gerecke To: linux-input@vger.kernel.org, Benjamin Tissoires , Jiri Kosina Cc: Ping Cheng , Aaron Armstrong Skomra , Joshua Dickens , Jason Gerecke , Jason Gerecke , Mario Limonciello Subject: [PATCH 1/2] HID: wacom: Lazy-init batteries Date: Thu, 13 Apr 2023 11:17:42 -0700 Message-Id: <20230413181743.7849-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Jason Gerecke Rather than creating batteries as part of the initial device probe, let's make the process lazy. This gives us the opportunity to prevent batteries from being created in situations where they are unnecessary. There are two cases in particular where batteries are being unnecessarily created at initialization. These are AES sensors (for which we don't know any battery status information until a battery-powered pen actually comes into prox) peripheral tablets which share HID descriptors between the wired-only and wireless-capable SKUs of a family of devices. This patch will delay battery initialization of the former until a pen actually comes into prox. It will delay battery initialization of the latter until either a pen comes into prox or a "heartbeat" packet is processed. Signed-off-by: Jason Gerecke Tested-by: Mario Limonciello --- drivers/hid/wacom_sys.c | 10 ---------- drivers/hid/wacom_wac.c | 13 ++++++------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index fb538a6c4add8..8214896adadad 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2372,13 +2372,6 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless) if (error) goto fail; - if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) && - (features->quirks & WACOM_QUIRK_BATTERY)) { - error = wacom_initialize_battery(wacom); - if (error) - goto fail; - } - error = wacom_register_inputs(wacom); if (error) goto fail; @@ -2509,9 +2502,6 @@ static void wacom_wireless_work(struct work_struct *work) strscpy(wacom_wac->name, wacom_wac1->name, sizeof(wacom_wac->name)); - error = wacom_initialize_battery(wacom); - if (error) - goto fail; } return; diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 4cfa51416dbcb..391fde5bf6024 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -113,6 +113,11 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac, bool bat_connected, bool ps_connected) { struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); + bool bat_initialized = wacom->battery.battery; + bool has_quirk = wacom_wac->features.quirks & WACOM_QUIRK_BATTERY; + + if (bat_initialized != has_quirk) + wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY); __wacom_notify_battery(&wacom->battery, bat_status, bat_capacity, bat_charging, bat_connected, ps_connected); @@ -3391,19 +3396,13 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) int battery = (data[8] & 0x3f) * 100 / 31; bool charging = !!(data[8] & 0x80); + features->quirks |= WACOM_QUIRK_BATTERY; wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO, battery, charging, battery || charging, 1); - - if (!wacom->battery.battery && - !(features->quirks & WACOM_QUIRK_BATTERY)) { - features->quirks |= WACOM_QUIRK_BATTERY; - wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY); - } } else if ((features->quirks & WACOM_QUIRK_BATTERY) && wacom->battery.battery) { features->quirks &= ~WACOM_QUIRK_BATTERY; - wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY); wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0); } return 0; From patchwork Thu Apr 13 18:17:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 673521 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 4677BC77B71 for ; Thu, 13 Apr 2023 18:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbjDMSSI (ORCPT ); Thu, 13 Apr 2023 14:18:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbjDMSSB (ORCPT ); Thu, 13 Apr 2023 14:18:01 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 798418689 for ; Thu, 13 Apr 2023 11:17:51 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-54fc337a650so47084387b3.4 for ; Thu, 13 Apr 2023 11:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681409870; x=1684001870; 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=lbgaqt9S6wRblWIya0iAYomPL2Ki6P5qw7xRjL8xJ7Y=; b=UeaYMbFz3lPJB+rGsc4cbz81/Dc95KrTHvvgab1h+qJqEY3CSZUkDOYwY2gjzK4qU5 P91r/tDBgPMPy3JeatYAWDLU+3F19gJDRETp4Y5GFoKzH0fNlB91Ivv8zjrOA7+LKXSn 0Gw3S2ee01YzXJ2pKdk93gb+yZFxCC7zQTeeOE7Bb9NId1SGztaUXjnW6Ho1HEwBVsq6 VTNLwDKEwL/sLspcQ6iRZFgiLotrJFU5q868bW9bbMJ15PCCzrnj5PiJD7VLvaelbF6W YaoK95u1ESGn7GYcTQQ8leL7WZDbsR7NZ94qORkUUartn6eieaG5OiffsOs7f0Egsbey Osww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681409870; x=1684001870; 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=lbgaqt9S6wRblWIya0iAYomPL2Ki6P5qw7xRjL8xJ7Y=; b=K5klc4EjZwQVvJoYKdCtBEAo0apMl6hPuv7bB6QYRQzK+XGrLM/fnIN+8uwejGbw7I sHiQoULpAxcJn9AVh8ieuhziLaoXN/65z1ztP3DHvfIiuB24g4DQVCpgmtMSNR80C+1F w2rgXHVml6ae38+F3RydlCSJa0d4ZX14yJOH+G5hMl9owkLc2PO91NfYw7rKKqljQkHQ Qn6uuGkij7HZtJHC1BZtwlEjH7GLVgTjby0Z10Ua1qo+B/IYAG86hgekS37eEU0hrI4I 0JRSbqvkyySVKF3Afs4XRf2wTrJsUVqp4RdHMkewWnHcy9YDd9AohgClBaZWCK/xY/UT /V6A== X-Gm-Message-State: AAQBX9eveA9BMwoWKPHYSnRhO1zVpEZEuTaks1zPjXI7mYqdqcz8f5Uu RORlPSyuAGB+9ae2U/7WsXMMqXTJ7JSDGg== X-Google-Smtp-Source: AKy350bUs7kYxMSBhdXsZj14nGU55szC9OwEzqDvVG8lPhLgG/8jpCWBKsibS2TnChIU+zY17r5Jxw== X-Received: by 2002:a0d:e253:0:b0:536:cb21:7223 with SMTP id l80-20020a0de253000000b00536cb217223mr2892982ywe.6.1681409870353; Thu, 13 Apr 2023 11:17:50 -0700 (PDT) Received: from horus.lan (71-34-68-4.ptld.qwest.net. [71.34.68.4]) by smtp.gmail.com with ESMTPSA id l9-20020a817009000000b00545a08184aasm641547ywc.58.2023.04.13.11.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:17:50 -0700 (PDT) From: Jason Gerecke X-Google-Original-From: Jason Gerecke To: linux-input@vger.kernel.org, Benjamin Tissoires , Jiri Kosina Cc: Ping Cheng , Aaron Armstrong Skomra , Joshua Dickens , Jason Gerecke , Jason Gerecke , Mario Limonciello Subject: [PATCH 2/2] HID: wacom: generic: Set battery quirk only when we see battery data Date: Thu, 13 Apr 2023 11:17:43 -0700 Message-Id: <20230413181743.7849-2-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230413181743.7849-1-jason.gerecke@wacom.com> References: <20230413181743.7849-1-jason.gerecke@wacom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Jason Gerecke Some devices will include battery status usages in the HID descriptor but we won't see that battery data for one reason or another. For example, AES sensors won't send battery data unless an AES pen is in proximity. If a user does not have an AES pen but instead only interacts with the AES touchscreen with their fingers then there is no need for us to create a battery object. Similarly, if a family of peripherals shares the same HID descriptor between wired-only and wireless-capable SKUs, users of the former may never see a battery event and will not want a power_supply object created. Signed-off-by: Jason Gerecke Tested-by: Mario Limonciello --- drivers/hid/wacom_wac.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 391fde5bf6024..5db7de7a6b171 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1960,18 +1960,7 @@ static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage, static void wacom_wac_battery_usage_mapping(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage) { - struct wacom *wacom = hid_get_drvdata(hdev); - struct wacom_wac *wacom_wac = &wacom->wacom_wac; - struct wacom_features *features = &wacom_wac->features; - unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); - - switch (equivalent_usage) { - case HID_DG_BATTERYSTRENGTH: - case WACOM_HID_WD_BATTERY_LEVEL: - case WACOM_HID_WD_BATTERY_CHARGING: - features->quirks |= WACOM_QUIRK_BATTERY; - break; - } + return; } static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field, @@ -1992,18 +1981,21 @@ static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *f wacom_wac->hid_data.bat_connected = 1; wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO; } + wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY; break; case WACOM_HID_WD_BATTERY_LEVEL: value = value * 100 / (field->logical_maximum - field->logical_minimum); wacom_wac->hid_data.battery_capacity = value; wacom_wac->hid_data.bat_connected = 1; wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO; + wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY; break; case WACOM_HID_WD_BATTERY_CHARGING: wacom_wac->hid_data.bat_charging = value; wacom_wac->hid_data.ps_connected = value; wacom_wac->hid_data.bat_connected = 1; wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO; + wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY; break; } } @@ -2019,18 +2011,15 @@ static void wacom_wac_battery_report(struct hid_device *hdev, { struct wacom *wacom = hid_get_drvdata(hdev); struct wacom_wac *wacom_wac = &wacom->wacom_wac; - struct wacom_features *features = &wacom_wac->features; - if (features->quirks & WACOM_QUIRK_BATTERY) { - int status = wacom_wac->hid_data.bat_status; - int capacity = wacom_wac->hid_data.battery_capacity; - bool charging = wacom_wac->hid_data.bat_charging; - bool connected = wacom_wac->hid_data.bat_connected; - bool powered = wacom_wac->hid_data.ps_connected; + int status = wacom_wac->hid_data.bat_status; + int capacity = wacom_wac->hid_data.battery_capacity; + bool charging = wacom_wac->hid_data.bat_charging; + bool connected = wacom_wac->hid_data.bat_connected; + bool powered = wacom_wac->hid_data.ps_connected; - wacom_notify_battery(wacom_wac, status, capacity, charging, - connected, powered); - } + wacom_notify_battery(wacom_wac, status, capacity, charging, + connected, powered); } static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,