Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp480825imd; Sat, 3 Nov 2018 04:29:48 -0700 (PDT) X-Google-Smtp-Source: AJdET5daOiTbunfMYpxoWBqimeNzCseAleDDFTz279oJwcaaE3kVkX1fYW5jCWd34qbwlIlmp2MH X-Received: by 2002:a63:9dca:: with SMTP id i193-v6mr12979913pgd.98.1541244588021; Sat, 03 Nov 2018 04:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541244587; cv=none; d=google.com; s=arc-20160816; b=oC3N6NMzZQMyoNKKZ1JfZ7UYWmyR1XEcfyRIO5qB0PbZEMv70J3uxsYcpoxcko2YYI 6xkhzwmqd8/InBl0URL95DRsoSgDuiIRm8ahOdsmRxDBgGrOlT63lab80/kvXnMa93R7 8xf0GlqAPv78VGLweDioeWHjCxuOXkkLYNzl+IEi/Z26eOCdrLtFcXg/PLcQ5/p5qV9k lvrxmpI5vI74jSRWuNonWKe6CC1READQZ678enpkQEdeyc/Cx69/EqBdpQDWmlMfet39 pl7NqQY2UkjBp5/jYZZia373IEmgeKu3QEqD73SbtqQ1YNIAHCoTOvCX1ZI1PXGggZnU 9wCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=tcn453aKtJMMgOUsdjfmS9udrKLA238Cvi+vA+ASh70=; b=J+uvqAAMiEzOnUD1dJfAvHhOzTb9PK/YvvdJEvwy0cMCh9U2tLWNy68FYTaCpuuoeu dDs7hMOsN4qA1ZV992JFBwz1T4t2JQmoeHw4cQI0DbYve9lcnw2CZypWiAxyWkYNBoq8 DEBquGIEFkjvxGeU4BOURgjTssjRJZxMOFzkrqtIMfcMjDTm7JJLfEhDxA9x/GIThsLa rykZGfE1Ff2f5vPIKnDltFIL6xvMKxbvgfyl7o51i8uRKlEXL9o+d0MURVgxz5l2Pkr0 RtgDYVgixzONeDeeZ05w8qcotYRT7El/vuKW1ArdT57X/LQDkOFr3A0jKz3q43PCo9cT 060A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b137-v6si29198752pfb.144.2018.11.03.04.29.20; Sat, 03 Nov 2018 04:29:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeKCUjr (ORCPT + 99 others); Sat, 3 Nov 2018 16:39:47 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43119 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbeKCUjr (ORCPT ); Sat, 3 Nov 2018 16:39:47 -0400 Received: by mail-ed1-f66.google.com with SMTP id y20-v6so3771005eds.10 for ; Sat, 03 Nov 2018 04:28:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=tcn453aKtJMMgOUsdjfmS9udrKLA238Cvi+vA+ASh70=; b=iBWiKwyUfoa5k8xc4/elqDNEFpdD4Cj5+tKUhepw0rFHWpxeZEgGgO5SyD44Pz2i1F 5Y5mQrG8epIY2KXJ3vS9m18jjk3+O/Nn+vT5uSezrSXs1KS60qfuLlVn2TaA54J9Lr94 lQchHNh8SB5mWRY1yfsSROQlpzZ3TZLbNMsmcXwhr9ExlNLqen3WqALA7wV0NM1xkhyq MNbyqwTe8jNiSp9yFYoN1sYCrgLkyqoVCLMYeAKiBmy4wHCuC3KLUJr8uxk6jExk3Wgp rVDT0toRXdLJ8sXeLlFlF123dDWqS+T8L/mgQeCRstakZKMXMRJtGV0/+zMLOrcebecC jfBg== X-Gm-Message-State: AGRZ1gLnh5VG/nigrI3w5IW9OJOT0LKC6fHi+ZkgLmbzHQYywleDW3qO YJDgmcKdc4uXQAx842tc7/tG6g== X-Received: by 2002:a05:6402:1609:: with SMTP id f9mr418019edv.35.1541244525479; Sat, 03 Nov 2018 04:28:45 -0700 (PDT) Received: from shalem.localdomain (546A5441.cm-12-3b.dynamic.ziggo.nl. [84.106.84.65]) by smtp.gmail.com with ESMTPSA id x21-v6sm10426255eds.30.2018.11.03.04.28.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 04:28:44 -0700 (PDT) Subject: Re: [PATCH] ACPI / battery: Fix reporting "Not charging" when capacity is 100% To: =?UTF-8?Q?Jo=c3=a3o_Paulo_Rechi_Vita?= , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Daniel Drake , Sebastian Reichel , linux-kernel@vger.kernel.org, linux@endlessm.com, =?UTF-8?Q?Jo=c3=a3o_Paulo_Rechi_Vita?= References: <20181103065732.12134-1-jprvita@endlessm.com> From: Hans de Goede Message-ID: <566af8d6-638e-8c7b-71b4-a7a8d6e71cdb@redhat.com> Date: Sat, 3 Nov 2018 12:28:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20181103065732.12134-1-jprvita@endlessm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 03-11-18 07:57, João Paulo Rechi Vita wrote: > Commit 19fffc8450d4378580a8f019b195c4617083176f fixed reporting > "Discharging" on some machines when AC was connected but the battery was > not charging. But now on these machines the battery status is reported > as "Not charging" even when the battery is fully charged. > > This commit takes the battery capacity into consideration when checking > if "Not charging" should be returned and "Full" is returned when the > capacity is 100%. > > Signed-off-by: João Paulo Rechi Vita acpi_battery_handle_discharging() only gets called if the ACPI_BATTERY_STATE_DISCHARGING bit is set by the firmware in that case if we are not actually discharging returning POWER_SUPPLY_STATUS_NOT_CHARGING is the only correct thing to do, we should never return POWER_SUPPLY_STATUS_FULL when the ACPI_BATTERY_STATE_DISCHARGING bit is set. I was about to point you to the upower bug for upower not handling POWER_SUPPLY_STATUS_NOT_CHARGING as well as it could atm, but I see you've already found that and are working on fixing that. That is great, thank you. As for this kernel-side fix I do not believe that fixing thus in the kernel is the right thing to do. We try to stay away from heuristics using full_charge_capacity in the kernel since that is not really reliable / deterministic. Regards, Hans > --- > drivers/acpi/battery.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index cb97b6105f52..82e194290f01 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -217,8 +217,12 @@ static int acpi_battery_handle_discharging(struct acpi_battery *battery) > * was plugged in and the device thus did not start a new charge cycle. > */ > if ((battery_ac_is_broken || power_supply_is_system_supplied()) && > - battery->rate_now == 0) > + battery->rate_now == 0) { > + if (battery->capacity_now && battery->full_charge_capacity && > + battery->capacity_now / battery->full_charge_capacity == 1) > + return POWER_SUPPLY_STATUS_FULL; > return POWER_SUPPLY_STATUS_NOT_CHARGING; > + } > > return POWER_SUPPLY_STATUS_DISCHARGING; > } >