From patchwork Wed Feb 7 14:59:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10205359 X-Patchwork-Delegate: rjw@sisk.pl 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 A6AD86020F for ; Wed, 7 Feb 2018 14:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 900F728D65 for ; Wed, 7 Feb 2018 14:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8485E28FA8; Wed, 7 Feb 2018 14:59:45 +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=unavailable 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 1B3C428D65 for ; Wed, 7 Feb 2018 14:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754516AbeBGO7n (ORCPT ); Wed, 7 Feb 2018 09:59:43 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35646 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754450AbeBGO7l (ORCPT ); Wed, 7 Feb 2018 09:59:41 -0500 Received: by mail-wm0-f68.google.com with SMTP id r78so3909562wme.0; Wed, 07 Feb 2018 06:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=cIA15NyfP5DeU0XJF2Z2OT4xTHKV7r4ed4DRVf3Qoa8=; b=KSqL86CdC+4J3EUw1C1PI+134HBPV8yG49AKlt0DP1GPDf/A23LGY5tNX1xtHSRxYh IcPM/Vq9g+TkiMkDvwnaKmh97lWuy47gMsPg22lb0NgOPfzjlVKoOyY2rHrQRycmbgYs Jq/+7y/Xmpvgn7exr6r2ekDfMaleUjM51TbvTuwgddZ6q8apCGN4tf6tNoB/xDmHnu8o u26va9984a9stEHObTLfZVWmcG6irgOq3+o/HVCWs52oDdCK9D8K9R+61NKY7QLthl18 3TWsJa231SowLt5HleH5qMfejpGl/I0vc9yk3Gur9DXKNG0TXH+rqph+n66kOxscAwXT 6Tgw== 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:subject:message-id:mime-version :content-disposition:user-agent; bh=cIA15NyfP5DeU0XJF2Z2OT4xTHKV7r4ed4DRVf3Qoa8=; b=LWkT6BIfNOlOuXqmQrigo755r0vQT4m4E8YPiSARmEUcaWY5Dm4n3Ek69IJVhd59Xe 1lkTtus8VqamkH2ZiVxi6aoTsrTBI+Yfi3MH2L+rfoVy11+TBFGp3aJOm+2y/nTOkWyj MNkVwcDkwt/0YMTJcWd5IfCZmokFCta9WIwUcRsZm/WXO1Orrs9R0Di7J81g1uLbs3vO uqGZSu3bmcnblmOAyCVVHDZXDDI2teF9L29GEz4u3RERlcQKkQGx0BZjqWm6R/GCArj2 DAgfap6G980i2t79NFrEu/4blmBUxJCEd4nga0QAODIpKNAxVDgFzi98kqqj8SAYLx9d c+Pw== X-Gm-Message-State: APf1xPB1+/bUUrgGwzJUyNNxOc5DCwCZjlyijFfUTZXq2bLTbYT+Gdd0 8b/1c4dEKOmBaeetFalevvk= X-Google-Smtp-Source: AH8x226bm88AdKDESzIFjSkMF/3+9qoshhwL57YVK2RG/3LQ+5FhYZJdtZfsBGK45h5hwlbIbLfpJQ== X-Received: by 10.28.216.149 with SMTP id p143mr5353789wmg.140.1518015579901; Wed, 07 Feb 2018 06:59:39 -0800 (PST) Received: from thinkpad (pppoe-46-239-10-245.teol.net. [46.239.10.245]) by smtp.googlemail.com with ESMTPSA id u98sm4422166wrc.69.2018.02.07.06.59.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Feb 2018 06:59:38 -0800 (PST) Date: Wed, 7 Feb 2018 15:59:36 +0100 From: Ognjen Galic To: Andy Shevchenko , "Rafael J. Wysocki" , Ognjen =?utf-8?B?R2FsacSH?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Lv Zheng , ACPI Devel Maling List , devel@acpica.org, Darren Hart , Andy Shevchenko , Henrique de Moraes Holschuh , Sebastian Reichel , Platform Driver , ibm-acpi-devel@lists.sourceforge.net, Linux PM , Christoph =?iso-8859-1?Q?B=F6hmwalder?= , Kevin Locke Subject: [PATCH v13 4/4] battery: Add the ThinkPad "Not Charging" quirk Message-ID: <20180207145936.ockmmkipxtwkdsot@thinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) 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. Reviewed-by: Andy Shevchenko Signed-off-by: Ognjen Galic --- Notes: v7: * Added all the style changes as suggested by Rafael * Re-ordered the series to make this a post-implement bugfix v8: * No changes in this patch in v8 v9: * No changes in this patch in v9 v10: * No changes in this patch in v10 v11: * Fix formatting of changelog v12: * No changes in this patch in v12 v13: * No changes in this patch in v13 drivers/acpi/battery.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 3fab2cb9e..e4b23738c 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -74,6 +74,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_notcharging; static int battery_full_discharging; static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); @@ -229,6 +230,8 @@ 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_notcharging) + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; else val->intval = POWER_SUPPLY_STATUS_UNKNOWN; break; @@ -707,7 +710,7 @@ EXPORT_SYMBOL_GPL(battery_hook_register); * This function gets called right after the battery sysfs * attributes have been added, so that the drivers that * define custom sysfs attributes can add their own. -*/ + */ static void battery_hook_add_battery(struct acpi_battery *battery) { struct acpi_battery_hook *hook_node; @@ -1315,6 +1318,12 @@ static int __init battery_full_discharging_quirk(const struct dmi_system_id *d) return 0; } +static int __init battery_quirk_not_charging(const struct dmi_system_id *d) +{ + battery_quirk_notcharging = 1; + return 0; +} + static const struct dmi_system_id bat_dmi_table[] __initconst = { { .callback = battery_bix_broken_package_quirk, @@ -1348,6 +1357,19 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = { DMI_MATCH(DMI_PRODUCT_NAME, "UX305LA"), }, }, + { + /* + * On Lenovo ThinkPads the BIOS specification defines + * a state when the bits for charging and discharging + * are both set to 0. That state is "Not Charging". + */ + .callback = battery_quirk_not_charging, + .ident = "Lenovo ThinkPad", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"), + }, + }, {}, };