From patchwork Tue Apr 10 09:06:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10332631 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 96D6D60365 for ; Tue, 10 Apr 2018 09:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86ED828C56 for ; Tue, 10 Apr 2018 09:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B60028C5B; Tue, 10 Apr 2018 09:07:39 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 26E4A28C56 for ; Tue, 10 Apr 2018 09:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753194AbeDJJGu (ORCPT ); Tue, 10 Apr 2018 05:06:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34857 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753126AbeDJJGs (ORCPT ); Tue, 10 Apr 2018 05:06:48 -0400 Received: by mail-wm0-f65.google.com with SMTP id r82so22027403wme.0; Tue, 10 Apr 2018 02:06:47 -0700 (PDT) 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=22+GXspBEnoWdR/t9pthfOvdTJQmZo+Z49ldGl44qn0=; b=hNsNUY08lCBtBOMG0jpmcYGJTQ/oHbOu0KWh+0JIuwzNUkQznoWaqE5kajigEjmWT0 eOXJztoEBfWv2nQuGV9BH3LQVEPuMKA5PPVlv4Zovyh1LfbqkVuc1hFjo6WpsVgkwtYH bCjAwGM6yl04MI7f2CjxsoWt8LlnwqSguPC+Xs8RjWn/w/XRkiYD42IPh3HkuTdAFAc1 FLUVA0EBFnxefRBsFu0R+3S6SqirIaqyyblCddqXDdHUnrTSE5JpHLuHAc6SY64lUCT7 UWO8sTH78fgEYOzu168buEmk2CGRhLqiXpm8w0ek+dMiswGrV1piS+GWpljFqAcsJLWw +MbQ== 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=22+GXspBEnoWdR/t9pthfOvdTJQmZo+Z49ldGl44qn0=; b=VmhiaoxN7+LmTTE752MNWckZTbU8BC8WIErVWNqp0seSWD/gSvD2qYUDhouQtU8nZT 59y+uZ5m1avMydSy97ajovhzpahkHyycfYoSOHF7nHSY0Hua0OwEHdVAE66RgRuaa9Ie Ho1FtAR32et8K+KkYP46gK4jT3OkkAMrmCPr6Ll3re2UPbwrRL8oFZ0T3fqmKaig3DBf yOm8omIxVs8cA54nuLoJO3pyUIfgnTPv/sdihtvkH9/1Ansk5IjB2hWZMfnjP6BFT/G4 A7r9vyMttkQfxzHWE3HDS+1nhAE/yAgA/UnjP/w3YItZI/EIAB5l2inXFIIghcVNOCWb Vizg== X-Gm-Message-State: ALQs6tDZ3Agpg59XiaXlhdBbV+l9PeUqHgj9yNbgc1Hd2kl6AxGqZY+A SH9gNeJW3VAIuFuWWx7Fi/4= X-Google-Smtp-Source: AIpwx4+NmjaJeKPIjjJ6Qgv1GlyLS8I4HgQuWTa2zAwfdmzVfne/ElIFYrZSQRjE4KedkGffSn+lbQ== X-Received: by 10.80.169.197 with SMTP id n63mr2009891edc.20.1523351207268; Tue, 10 Apr 2018 02:06:47 -0700 (PDT) Received: from thinkpad (pppoe-46-239-8-239.teol.net. [46.239.8.239]) by smtp.googlemail.com with ESMTPSA id s8sm1441159edk.76.2018.04.10.02.06.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Apr 2018 02:06:46 -0700 (PDT) Date: Tue, 10 Apr 2018 11:06:43 +0200 From: Ognjen Galic To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] battery: Add the ThinkPad battery status quirk Message-ID: <20180410090643.GA26554@thinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) 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 fix the "Unknown" state. The chosen new state when the battery is not charging is "Fully Charged" because a status of "Not Charging" breaks almost all applications in userspace that depend on upower, because upower in itself can't handle a state of "Not Charging", defaulting to "Unknown". When we report "Fully Charged" instead of "Unknown", the userspace handles everything just fine, displaying for example: "Fully Charged, 59%" in Xfce. This is a re-write of: https://patchwork.kernel.org/patch/10205359/ Signed-off-by: Ognjen Galic --- drivers/acpi/battery.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index bdb24d63..cb4457a7 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_thinkpad_full; static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); @@ -233,7 +234,8 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_STATUS_DISCHARGING; else if (battery->state & ACPI_BATTERY_STATE_CHARGING) val->intval = POWER_SUPPLY_STATUS_CHARGING; - else if (acpi_battery_is_charged(battery)) + else if (acpi_battery_is_charged(battery) || + battery_quirk_thinkpad_full) val->intval = POWER_SUPPLY_STATUS_FULL; else val->intval = POWER_SUPPLY_STATUS_UNKNOWN; @@ -1332,6 +1334,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d) return 0; } +static int __init +battery_thinkpad_full_charged_quirk(const struct dmi_system_id *d) +{ + battery_quirk_thinkpad_full = 1; + return 0; +} + static const struct dmi_system_id bat_dmi_table[] __initconst = { { .callback = battery_bix_broken_package_quirk, @@ -1349,6 +1358,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = { DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"), }, }, + { + .callback = battery_thinkpad_full_charged_quirk, + .ident = "Lenovo ThinkPad", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"), + }, + }, {}, };