linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "João Paulo Rechi Vita" <jprvita@gmail.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	"Len Brown" <lenb@kernel.org>,
	linux-acpi@vger.kernel.org
Cc: "Daniel Drake" <drake@endlessm.com>,
	"Sebastian Reichel" <sebastian.reichel@collabora.co.uk>,
	linux-kernel@vger.kernel.org, linux@endlessm.com,
	"João Paulo Rechi Vita" <jprvita@endlessm.com>
Subject: Re: [PATCH] ACPI / battery: Fix reporting "Not charging" when capacity is 100%
Date: Sat, 3 Nov 2018 12:28:43 +0100	[thread overview]
Message-ID: <566af8d6-638e-8c7b-71b4-a7a8d6e71cdb@redhat.com> (raw)
In-Reply-To: <20181103065732.12134-1-jprvita@endlessm.com>

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 <jprvita@endlessm.com>

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;
>   }
> 

  reply	other threads:[~2018-11-03 11:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-03  6:57 [PATCH] ACPI / battery: Fix reporting "Not charging" when capacity is 100% João Paulo Rechi Vita
2018-11-03 11:28 ` Hans de Goede [this message]
2018-11-06 20:14   ` João Paulo Rechi Vita
2018-11-05  9:19 ` Pavel Machek
2018-11-06 20:34   ` João Paulo Rechi Vita
2018-11-07  4:53     ` Daniel Drake
2018-11-11 11:57       ` Hans de Goede
2018-11-11 12:22         ` Pavel Machek
2018-11-20  2:12           ` João Paulo Rechi Vita
2018-11-20  9:16             ` Pavel Machek
2018-11-11 11:30     ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=566af8d6-638e-8c7b-71b4-a7a8d6e71cdb@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=drake@endlessm.com \
    --cc=jprvita@endlessm.com \
    --cc=jprvita@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@endlessm.com \
    --cc=rjw@rjwysocki.net \
    --cc=sebastian.reichel@collabora.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).