From patchwork Wed Dec 6 22:53:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10097353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56E8660327 for ; Wed, 6 Dec 2017 22:53:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 475B728C1C for ; Wed, 6 Dec 2017 22:53:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A75129271; Wed, 6 Dec 2017 22:53:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C91A828C1C for ; Wed, 6 Dec 2017 22:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbdLFWxL (ORCPT ); Wed, 6 Dec 2017 17:53:11 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39888 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752564AbdLFWxK (ORCPT ); Wed, 6 Dec 2017 17:53:10 -0500 Received: by mail-wm0-f67.google.com with SMTP id i11so9779312wmf.4; Wed, 06 Dec 2017 14:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=to19otRvo5qeii0Er0riUDEHsLkdZ0FNxeQtksvDOjk=; b=QVTvPslzLBw8+jysnEUsuIErDhPfFk/BFvq6qM7g5h5L5Yzm4dj/hstw7PwHG9lO0b WnfqxUSl/ybnr+WuVwpZWW52Rba5gM9nC98RBvTP9+hnrZiAt0Mwkglot470uih5wqo5 0/OSxA8crV8f+P1Lg3QUR/AdcmMKNHHRWlGztJEEnCgd86C5k1eChV6rrnzWfVzecfMo D1FVXka4syC/8+/Hs7eLn3qpqUWlQ/FgwXk5qYYcZf+/Hk+D+A+zwV47biclskLU2GUB Ygikw43UO9nfMUpghJipBJTbSvWrNhrcRB/QcbLJ1ZGSkvpwCe10P6z5Ve+2KplKVKvb vALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=to19otRvo5qeii0Er0riUDEHsLkdZ0FNxeQtksvDOjk=; b=kR7SOrF8S08dkFALSE9eUFFEKEOP0RidNdqW6M2bU21o67R+9Yk51zhK9D3LhJxBT5 m1mSyYXpUlZM3NAk0wWoWYOVK5cQvwDFssiUYiK16ybDl8M8x3E99c3b7bz/cQ9gNAKN 8pOGPtghkBFFWlBmGCI7/Fga0KyvQ+WpEDqzXGkHzzi6AyG28N8nR/eqq9oQlIGwwK7d kG/WTZvg3Xfhq5Nw2obnNMdT8+pBOXvI6yuZiAb0K+wEU43Xw736ZqqGe9Ms42y9UiSa 1Vd1uX8vdfETIorqzvBVu3p9EOVMkcm17hyK0aE3zNV/yjIuHrWV7zfxB8CKfYU5xdJG NCLg== X-Gm-Message-State: AKGB3mJe4lIdbuPUJXnK4l3OjynyqoBlmhEsRzGxOLMewf33jddH74Vg MyYVuZT7GPpzO5GNUfE25jqrcVPi X-Google-Smtp-Source: AGs4zMZtK+P8rmtafKBOCdJlL1iiw29X69jxEADYPwkaDn0fsCB1V/xcIeR6VQvGS2HYzgUZ7y0NPQ== X-Received: by 10.28.208.205 with SMTP id h196mr6572070wmg.160.1512600783854; Wed, 06 Dec 2017 14:53:03 -0800 (PST) Received: from thinkpad (pppoe-46-239-10-202.teol.net. [46.239.10.202]) by smtp.gmail.com with ESMTPSA id u33sm4134410wrb.68.2017.12.06.14.53.02 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Dec 2017 14:53:02 -0800 (PST) Date: Wed, 6 Dec 2017 23:53:01 +0100 From: Ognjen Galic To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lv Zheng , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devel@acpica.org Cc: Henrique de Moraes Holschuh , Darren Hart , Andy Shevchenko , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] battery: Add the ThinkPad "Not Charging" quirk Message-ID: <20171206225301.GA3837@thinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly. Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging. Signed-off-by: Ognjen Galic --- drivers/acpi/battery.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 2951d07..1afc9c7 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -57,6 +57,13 @@ #define ACPI_BATTERY_STATE_DISCHARGING 0x1 #define ACPI_BATTERY_STATE_CHARGING 0x2 #define ACPI_BATTERY_STATE_CRITICAL 0x4 +/* + * On Lenovo ThinkPads the ACPI firmware + * returns a custom response when the battery + * is configured with wear control and the battery + * is between the start and stop charge thresholds. + */ +#define ACPI_BATTERY_STATE_NOT_CHARGING 0x8 #define _COMPONENT ACPI_BATTERY_COMPONENT @@ -71,6 +78,7 @@ static async_cookie_t async_cookie; static bool battery_driver_registered; static int battery_bix_broken_package; static int battery_notification_delay_ms; +static int battery_quirk_thinkpad_notcharging; static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); @@ -222,6 +230,9 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_STATUS_CHARGING; else if (acpi_battery_is_charged(battery)) val->intval = POWER_SUPPLY_STATUS_FULL; + else if (battery_quirk_thinkpad_notcharging && + val->intval & ACPI_BATTERY_STATE_NOT_CHARGING) + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; else val->intval = POWER_SUPPLY_STATUS_UNKNOWN; break; @@ -1301,6 +1312,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d) return 0; } +static int __init +battery_quirk_not_charging(const struct dmi_system_id *d) +{ + battery_quirk_thinkpad_notcharging = 1; + return 0; +} + static const struct dmi_system_id bat_dmi_table[] __initconst = { { .callback = battery_bix_broken_package_quirk, @@ -1318,6 +1336,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = { DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"), }, }, + { + .callback = battery_quirk_not_charging, + .ident = "Lenovo ThinkPad", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"), + }, + }, {}, };