Received: by 10.213.65.68 with SMTP id h4csp3640349imn; Tue, 10 Apr 2018 02:10:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+OiiI7JyOtKxZDI07YC9D9iAg49wpSEFuopyn1KeXUwqtrucTC5S36vjs+DPwPeeLwMmV1 X-Received: by 10.99.177.78 with SMTP id g14mr6349000pgp.253.1523351421195; Tue, 10 Apr 2018 02:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523351421; cv=none; d=google.com; s=arc-20160816; b=W+5pE8XK7jUZE/7Wc510VVGekKB3QoTqoqG+xHuX6hN5Ie4MmcNzgnVj7UNvfDQz+K cBoTdfhSdqtC8EQ++HEHY+WCIbthOzXRpp8DZBhQE6ho5VKgFRMnJbuU1nw7ETTccF8i qoOQgmjDHifxflvWRysAuKgw6e7t5M6j++UbiKW9j2FunKXi+/pUZfe82zM7cP69/02i yxcE91deMPwVQq9YW14ZJm7rEzpCkeVNvX4pQnDa2++lojQ83cmBsKP0YGOnrv5RPPRt P33nQSnQomvur+Pp/4ZPMAiVP7BOpJSm2/WlHoVjGuwRiu0lUnFT+NNU89oEEpuir4yt P4gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :arc-authentication-results; bh=22+GXspBEnoWdR/t9pthfOvdTJQmZo+Z49ldGl44qn0=; b=ZvF/lDAtivUQzcZYUJu/lpB+UGIFIP2Vg2bCB4SU+/G+8sbybuW77K5XhWJx+9ouyc J+2pCyLkbllSiKdFJpCmeoEfj0dLc77GLijvefkEpG8vOaTbn4JKqDFlOTNxKWU0xMfn +VjRcD9/Sz5Jhnv44IIHmDMS1fGqFX4hpNLGwxk7eTpfbKm6LH7ApvsL7R5I01hbq0J2 ZJFR6pZyUdMQXn8YfB/3THo2cMSAc6hk/VfsLJyqPyX8ju+AOIJ4AXxw7r3efyEX+Lrj Uu6oLNH18nZjc44jRL6s6FHU1KU7V5kV+6eSD1RtCiwyD2fxTSvB76U3sKHK2L2vP/1O rckg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hNsNUY08; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si1558785pgn.372.2018.04.10.02.09.44; Tue, 10 Apr 2018 02:10:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hNsNUY08; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1753209AbeDJJGv (ORCPT + 99 others); Tue, 10 Apr 2018 05:06:51 -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-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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"), + }, + }, {}, }; -- 2.15.1