[PATCH v5 9/9] power: supply: qcom_battmgr: handle charging state change notifications

Fenglin Wu via B4 Relay posted 9 patches 2 weeks, 1 day ago
There is a newer version of this series
[PATCH v5 9/9] power: supply: qcom_battmgr: handle charging state change notifications
Posted by Fenglin Wu via B4 Relay 2 weeks, 1 day ago
From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>

The X1E80100 battery management firmware sends a notification with
code 0x83 when the battery charging state changes, such as switching
between fast charge, taper charge, end of charge, or any other error
charging states. The same notification code is used with bit[16] set
if charging stops due to reaching the charge control end threshold.
Additionally, a 2-bit value is added in bit[18:17] with the same code
and used to indicate the charging source capability: a value of 2
represents a strong charger, 1 is a weak charger, and 0 is no charging
source. The 3-MSB [18:16] in the notification code is not much useful
for now, hence just ignore them and trigger a power supply change event
whenever 0x83 notification code is received. This helps to eliminate the
unknown notification error messages.

Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
---
 drivers/power/supply/qcom_battmgr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 151cd5618ca5c70f941245e4df5a18d4778f1349..4056290b5d737f762d9adb2783d26bb50ec5a664 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -34,8 +34,9 @@ enum qcom_battmgr_variant {
 #define NOTIF_BAT_PROPERTY		0x30
 #define NOTIF_USB_PROPERTY		0x32
 #define NOTIF_WLS_PROPERTY		0x34
-#define NOTIF_BAT_INFO			0x81
 #define NOTIF_BAT_STATUS		0x80
+#define NOTIF_BAT_INFO			0x81
+#define NOTIF_BAT_CHARGING_STATE	0x83
 
 #define BATTMGR_BAT_INFO		0x9
 
@@ -1206,12 +1207,14 @@ static void qcom_battmgr_notification(struct qcom_battmgr *battmgr,
 	}
 
 	notification = le32_to_cpu(msg->notification);
+	notification &= 0xff;
 	switch (notification) {
 	case NOTIF_BAT_INFO:
 		battmgr->info.valid = false;
 		fallthrough;
 	case NOTIF_BAT_STATUS:
 	case NOTIF_BAT_PROPERTY:
+	case NOTIF_BAT_CHARGING_STATE:
 		power_supply_changed(battmgr->bat_psy);
 		break;
 	case NOTIF_USB_PROPERTY:

-- 
2.34.1
Re: [PATCH v5 9/9] power: supply: qcom_battmgr: handle charging state change notifications
Posted by Konrad Dybcio 2 weeks, 1 day ago
On 9/17/25 12:15 PM, Fenglin Wu via B4 Relay wrote:
> From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> 
> The X1E80100 battery management firmware sends a notification with
> code 0x83 when the battery charging state changes, such as switching
> between fast charge, taper charge, end of charge, or any other error
> charging states. The same notification code is used with bit[16] set
> if charging stops due to reaching the charge control end threshold.
> Additionally, a 2-bit value is added in bit[18:17] with the same code
> and used to indicate the charging source capability: a value of 2
> represents a strong charger, 1 is a weak charger, and 0 is no charging
> source. The 3-MSB [18:16] in the notification code is not much useful
> for now, hence just ignore them and trigger a power supply change event
> whenever 0x83 notification code is received. This helps to eliminate the
> unknown notification error messages.

Thank you for explaining the technical background.

Please hit enter somewhere in your commit message, this is a very
long paragraph, making it difficult to read.


I believe this maps to:

0 -> POWER_SUPPLY_CHARGE_TYPE_NONE
1 -> POWER_SUPPLY_CHARGE_TYPE_TRICKLE
2 -> POWER_SUPPLY_CHARGE_TYPE_FAST (or _STANDARD, I see battmgr code
reports them both as 2)

However, we already set it to none/trickle/standard(taper) based on
the usual notifications, so I'm not sure if these are more common or
arrive outside the normal state changes - if so, perhaps we can take
them into account as well?

I think it also warrants a:

Reported-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Konrad
Re: [PATCH v5 9/9] power: supply: qcom_battmgr: handle charging state change notifications
Posted by Fenglin Wu 2 weeks ago
On 9/17/2025 7:14 PM, Konrad Dybcio wrote:
> On 9/17/25 12:15 PM, Fenglin Wu via B4 Relay wrote:
>> From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
>>
>> The X1E80100 battery management firmware sends a notification with
>> code 0x83 when the battery charging state changes, such as switching
>> between fast charge, taper charge, end of charge, or any other error
>> charging states. The same notification code is used with bit[16] set
>> if charging stops due to reaching the charge control end threshold.
>> Additionally, a 2-bit value is added in bit[18:17] with the same code
>> and used to indicate the charging source capability: a value of 2
>> represents a strong charger, 1 is a weak charger, and 0 is no charging
>> source. The 3-MSB [18:16] in the notification code is not much useful
>> for now, hence just ignore them and trigger a power supply change event
>> whenever 0x83 notification code is received. This helps to eliminate the
>> unknown notification error messages.
> Thank you for explaining the technical background.
>
> Please hit enter somewhere in your commit message, this is a very
> long paragraph, making it difficult to read.
I just realized I made a mistake on the bit position, it should be 
bit[8] for reaching to the charge control threshold, bit[10:9] for 
charging source capability. I don't know what I was thinking when 
writing the commit text :(. I will correct them in the next patch.
>
> I believe this maps to:
>
> 0 -> POWER_SUPPLY_CHARGE_TYPE_NONE
> 1 -> POWER_SUPPLY_CHARGE_TYPE_TRICKLE
> 2 -> POWER_SUPPLY_CHARGE_TYPE_FAST (or _STANDARD, I see battmgr code
> reports them both as 2)
>
> However, we already set it to none/trickle/standard(taper) based on
> the usual notifications, so I'm not sure if these are more common or
> arrive outside the normal state changes - if so, perhaps we can take
> them into account as well?

This is not related with the real charging status. I double checked in 
the battery management firmware, it is checking the charging source 
power capability by multiplying maximum voltage and current reading from 
the PDOs. Any charger adapter with a maximum power below 60W is 
identified as a slow/weak charger.

>
> I think it also warrants a:
>
> Reported-by: Sebastian Reichel <sebastian.reichel@collabora.com>
ACK
> Konrad
Re: [PATCH v5 9/9] power: supply: qcom_battmgr: handle charging state change notifications
Posted by Sebastian Reichel 1 week, 6 days ago
Hi,

On Thu, Sep 18, 2025 at 10:01:24AM +0800, Fenglin Wu wrote:
> On 9/17/2025 7:14 PM, Konrad Dybcio wrote:
> > On 9/17/25 12:15 PM, Fenglin Wu via B4 Relay wrote:
> > > From: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> > > 
> > > The X1E80100 battery management firmware sends a notification with
> > > code 0x83 when the battery charging state changes, such as switching
> > > between fast charge, taper charge, end of charge, or any other error
> > > charging states. The same notification code is used with bit[16] set
> > > if charging stops due to reaching the charge control end threshold.
> > > Additionally, a 2-bit value is added in bit[18:17] with the same code
> > > and used to indicate the charging source capability: a value of 2
> > > represents a strong charger, 1 is a weak charger, and 0 is no charging
> > > source. The 3-MSB [18:16] in the notification code is not much useful
> > > for now, hence just ignore them and trigger a power supply change event
> > > whenever 0x83 notification code is received. This helps to eliminate the
> > > unknown notification error messages.
> > Thank you for explaining the technical background.
> > 
> > Please hit enter somewhere in your commit message, this is a very
> > long paragraph, making it difficult to read.
> I just realized I made a mistake on the bit position, it should be bit[8]
> for reaching to the charge control threshold, bit[10:9] for charging source
> capability. I don't know what I was thinking when writing the commit text
> :(. I will correct them in the next patch.
> > 
> > I believe this maps to:
> > 
> > 0 -> POWER_SUPPLY_CHARGE_TYPE_NONE
> > 1 -> POWER_SUPPLY_CHARGE_TYPE_TRICKLE
> > 2 -> POWER_SUPPLY_CHARGE_TYPE_FAST (or _STANDARD, I see battmgr code
> > reports them both as 2)
> > 
> > However, we already set it to none/trickle/standard(taper) based on
> > the usual notifications, so I'm not sure if these are more common or
> > arrive outside the normal state changes - if so, perhaps we can take
> > them into account as well?
> 
> This is not related with the real charging status. I double checked in the
> battery management firmware, it is checking the charging source power
> capability by multiplying maximum voltage and current reading from the PDOs.
> Any charger adapter with a maximum power below 60W is identified as a
> slow/weak charger.

Please include that info in the commit message when sending a v6.
The code change itself LGTM.

Thanks,

-- Sebastian