mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Auer <mick@yoxcu.de>
To: Sebastian Reichel <sre@kernel.org>
Cc: "Pali Rohár" <pali@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Michael Auer" <mick@yoxcu.de>
Subject: [PATCH 1/3] power: supply: bq27xxx: report discharging at zero current without a charger
Date: Sat, 21 Nov 2026 21:41:35 +0100	[thread overview]
Message-ID: <20261121204137.848173-2-mick@yoxcu.de> (raw)
In-Reply-To: <20261121204137.848173-1-mick@yoxcu.de>

The status is derived from the sign of the current, so a current of 0
is reported as "Not charging". On a OnePlus 6 (bq27541) the first
current reading after a resume from deep sleep is 0. User space then
sees "Not charging" while on battery: UPower no longer reports the
device as on battery, and the desktop plays its "power adapter plugged
in" sound after such resumes, until the next reading shows a negative
current again.

"Not charging" means a charger is present but not charging, so report
"Discharging" for a zero current when no power supply is online. Do it
only for the direct property read: the cached update runs under
di->lock, and power_supply_is_system_supplied() also reads properties
of this battery.

Signed-off-by: Michael Auer <mick@yoxcu.de>
---
 drivers/power/supply/bq27xxx_battery.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 747a38d3390d..032eea030f2f 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -1942,6 +1942,14 @@ static int bq27xxx_battery_current_and_status(
 			val_status->intval = POWER_SUPPLY_STATUS_CHARGING;
 		else if (curr < 0)
 			val_status->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+		else if (!cache && power_supply_is_system_supplied() == 0)
+			/*
+			 * No charger online: |current| is below the resolution (e.g. after
+			 * deep sleep). Only for the direct property read: the cached update
+			 * runs under di->lock, and power_supply_is_system_supplied() calls
+			 * get_property() on every supply, this battery included.
+			 */
+			val_status->intval = POWER_SUPPLY_STATUS_DISCHARGING;
 		else
 			val_status->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 	}
-- 
2.43.0


  reply	other threads:[~2026-11-21 20:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 20:41 [PATCH 0/3] power: supply: bq27xxx: fix wrong battery states after resume Michael Auer
2026-11-21 20:41 ` Michael Auer [this message]
2026-11-21 20:41 ` [PATCH 2/3] power: supply: bq27xxx: retry a failed register read once Michael Auer
2026-11-21 20:41 ` [PATCH 3/3] power: supply: bq27xxx: keep the last values over a short read failure Michael Auer

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=20261121204137.848173-2-mick@yoxcu.de \
    --to=mick@yoxcu.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=sre@kernel.org \
    /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

all inboxes | Powered by JetHome®