mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] power: supply: qcom_battmgr: report full batteries
@ 2026-10-08  9:14 Bjorn Andersson
  2026-10-13 11:21 ` Konrad Dybcio
  2026-10-17 23:17 ` Sebastian Reichel
  0 siblings, 2 replies; 4+ messages in thread
From: Bjorn Andersson @ 2026-10-08  9:14 UTC (permalink / raw)
  To: Sebastian Reichel, Bjorn Andersson, Neil Armstrong
  Cc: linux-arm-msm, Sebastian Reichel, linux-pm, linux-kernel,
	Bjorn Andersson

The SC8280XP battery-status response has no explicit full state. When a
battery reaches its full capacity on external power, neither the charging
nor discharging bit is set. The driver consequently reports "Not
charging", which can make userspace show the system as battery powered.

Use the response's power-online bit and the reported capacity to identify
a battery that is full while externally powered. Preserve "Not charging"
for a battery whose charging is inhibited below its full capacity.

Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply")
Assisted-by: LLM
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
---
 drivers/power/supply/qcom_battmgr.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 7716eb9e1aff..97cbe966ea84 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -1261,6 +1261,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,
 	unsigned int opcode = le32_to_cpu(resp->hdr.opcode);
 	unsigned int source;
 	unsigned int state;
+	unsigned int power_state;
 	size_t payload_len = len - sizeof(struct pmic_glink_hdr);
 
 	if (payload_len < sizeof(__le32)) {
@@ -1310,18 +1311,23 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,
 		}
 
 		state = le32_to_cpu(resp->status.battery_state);
+		battmgr->status.capacity = le32_to_cpu(resp->status.capacity) * 1000;
+		battmgr->status.power_now = le32_to_cpu(resp->status.rate) * 1000;
+		battmgr->status.voltage_now = le32_to_cpu(resp->status.battery_voltage) * 1000;
+		battmgr->status.temperature = qcom_battmgr_sc8280xp_convert_temp(le32_to_cpu(resp->status.temperature));
+
+		power_state = le32_to_cpu(resp->status.power_state);
 		if (state & BIT(0))
 			battmgr->status.status = POWER_SUPPLY_STATUS_DISCHARGING;
 		else if (state & BIT(1))
 			battmgr->status.status = POWER_SUPPLY_STATUS_CHARGING;
+		else if ((power_state & BIT(0)) &&
+			 battmgr->info.last_full_capacity &&
+			 battmgr->status.capacity >= battmgr->info.last_full_capacity)
+			battmgr->status.status = POWER_SUPPLY_STATUS_FULL;
 		else
 			battmgr->status.status = POWER_SUPPLY_STATUS_NOT_CHARGING;
 
-		battmgr->status.capacity = le32_to_cpu(resp->status.capacity) * 1000;
-		battmgr->status.power_now = le32_to_cpu(resp->status.rate) * 1000;
-		battmgr->status.voltage_now = le32_to_cpu(resp->status.battery_voltage) * 1000;
-		battmgr->status.temperature = qcom_battmgr_sc8280xp_convert_temp(le32_to_cpu(resp->status.temperature));
-
 		source = le32_to_cpu(resp->status.charging_source);
 		battmgr->ac.online = source == BATTMGR_CHARGING_SOURCE_AC;
 		battmgr->usb.online = source == BATTMGR_CHARGING_SOURCE_USB;

---
base-commit: f0406245cb9855e6318335a8a223551354291a46
change-id: 20261008-battmgr-full-0cc0c1b91bea

Best regards,
--  
Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: supply: qcom_battmgr: report full batteries
  2026-10-08  9:14 [PATCH] power: supply: qcom_battmgr: report full batteries Bjorn Andersson
@ 2026-10-13 11:21 ` Konrad Dybcio
  2026-10-17 23:23   ` Sebastian Reichel
  2026-10-17 23:17 ` Sebastian Reichel
  1 sibling, 1 reply; 4+ messages in thread
From: Konrad Dybcio @ 2026-10-13 11:21 UTC (permalink / raw)
  To: Bjorn Andersson, Sebastian Reichel, Bjorn Andersson, Neil Armstrong
  Cc: linux-arm-msm, Sebastian Reichel, linux-pm, linux-kernel

On 10/8/26 11:14 AM, Bjorn Andersson wrote:
> The SC8280XP battery-status response has no explicit full state. When a
> battery reaches its full capacity on external power, neither the charging
> nor discharging bit is set. The driver consequently reports "Not
> charging", which can make userspace show the system as battery powered.
> 
> Use the response's power-online bit and the reported capacity to identify
> a battery that is full while externally powered. Preserve "Not charging"
> for a battery whose charging is inhibited below its full capacity.

Let's define that bit, as it's not obvious what it corresponds to.

> 
> Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply")
> Assisted-by: LLM
> Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
> ---
>  drivers/power/supply/qcom_battmgr.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
> index 7716eb9e1aff..97cbe966ea84 100644
> --- a/drivers/power/supply/qcom_battmgr.c
> +++ b/drivers/power/supply/qcom_battmgr.c
> @@ -1261,6 +1261,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,
>  	unsigned int opcode = le32_to_cpu(resp->hdr.opcode);
>  	unsigned int source;
>  	unsigned int state;
> +	unsigned int power_state;

Reverse-Christmas-tree, please

Claude also has concerns regarding how this interacts with charge
limit (although perhaps "not charging" should be good there?)

with that resolved:

Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Konrad

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: supply: qcom_battmgr: report full batteries
  2026-10-08  9:14 [PATCH] power: supply: qcom_battmgr: report full batteries Bjorn Andersson
  2026-10-13 11:21 ` Konrad Dybcio
@ 2026-10-17 23:17 ` Sebastian Reichel
  1 sibling, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2026-10-17 23:17 UTC (permalink / raw)
  To: Sebastian Reichel, Bjorn Andersson, Neil Armstrong, Bjorn Andersson
  Cc: linux-arm-msm, linux-pm, linux-kernel


On Thu, 08 Oct 2026 11:14:57 +0200, Bjorn Andersson wrote:
> The SC8280XP battery-status response has no explicit full state. When a
> battery reaches its full capacity on external power, neither the charging
> nor discharging bit is set. The driver consequently reports "Not
> charging", which can make userspace show the system as battery powered.
> 
> Use the response's power-online bit and the reported capacity to identify
> a battery that is full while externally powered. Preserve "Not charging"
> for a battery whose charging is inhibited below its full capacity.
> 
> [...]

Applied, thanks!

[1/1] power: supply: qcom_battmgr: report full batteries
      commit: 6c8098e04ee4d233399e40e7311715844910f8f8

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: supply: qcom_battmgr: report full batteries
  2026-10-13 11:21 ` Konrad Dybcio
@ 2026-10-17 23:23   ` Sebastian Reichel
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2026-10-17 23:23 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Bjorn Andersson, Bjorn Andersson, Neil Armstrong, linux-arm-msm,
	linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

Hi,

On Tue, Oct 13, 2026 at 01:21:53PM +0200, Konrad Dybcio wrote:
> On 10/8/26 11:14 AM, Bjorn Andersson wrote:
> > The SC8280XP battery-status response has no explicit full state. When a
> > battery reaches its full capacity on external power, neither the charging
> > nor discharging bit is set. The driver consequently reports "Not
> > charging", which can make userspace show the system as battery powered.
> > 
> > Use the response's power-online bit and the reported capacity to identify
> > a battery that is full while externally powered. Preserve "Not charging"
> > for a battery whose charging is inhibited below its full capacity.
> 
> Let's define that bit, as it's not obvious what it corresponds to.
> 
> > 
> > Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply")
> > Assisted-by: LLM
> > Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
> > ---
> >  drivers/power/supply/qcom_battmgr.c | 16 +++++++++++-----
> >  1 file changed, 11 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
> > index 7716eb9e1aff..97cbe966ea84 100644
> > --- a/drivers/power/supply/qcom_battmgr.c
> > +++ b/drivers/power/supply/qcom_battmgr.c
> > @@ -1261,6 +1261,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,
> >  	unsigned int opcode = le32_to_cpu(resp->hdr.opcode);
> >  	unsigned int source;
> >  	unsigned int state;
> > +	unsigned int power_state;
> 
> Reverse-Christmas-tree, please

I fixed this while applying.

> Claude also has concerns regarding how this interacts with charge
> limit (although perhaps "not charging" should be good there?)

Not Charging generally means the system is powered externally and
the battery is neither charged not discharged. The Full state is
effectively a substate of Not Charging. So the main issue from Bjorn
is a userspace bug.

> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> Konrad

Greetings,

-- Sebastian



[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-17 23:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08  9:14 [PATCH] power: supply: qcom_battmgr: report full batteries Bjorn Andersson
2026-10-13 11:21 ` Konrad Dybcio
2026-10-17 23:23   ` Sebastian Reichel
2026-10-17 23:17 ` Sebastian Reichel

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®