]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
power: supply: max17042_battery: Use Current register in get_status
authorSebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Mon, 6 Apr 2026 20:57:50 +0000 (16:57 -0400)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 3 Jun 2026 19:29:39 +0000 (21:29 +0200)
It can take a while for AvgCurrent to adjust after (un)plugging the charger. Use the instantaneous value in order to not confuse the userspace.

While at that, don't do unit conversion of the read value. The current code was prone to overflows and we only care about the sign anyway.

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Link: https://patch.msgid.link/20260406205759.493288-3-vincent.cloutier@icloud.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/max17042_battery.c

index 103ce1d47aa845962cffdf1e6888c0a327d96b7f..e896cd169a91e2bfd79e67023771c30b67100000 100644 (file)
@@ -121,7 +121,7 @@ static int max17042_get_temperature(struct max17042_chip *chip, int *temp)
 static int max17042_get_status(struct max17042_chip *chip, int *status)
 {
        int ret, charge_full, charge_now;
-       int avg_current;
+       int current_now;
        u32 data;
 
        ret = power_supply_am_i_supplied(chip->battery);
@@ -166,14 +166,13 @@ static int max17042_get_status(struct max17042_chip *chip, int *status)
                return 0;
        }
 
-       ret = regmap_read(chip->regmap, MAX17042_AvgCurrent, &data);
+       ret = regmap_read(chip->regmap, MAX17042_Current, &data);
        if (ret < 0)
                return ret;
 
-       avg_current = sign_extend32(data, 15);
-       avg_current *= 1562500 / chip->pdata->r_sns;
+       current_now = sign_extend32(data, 15);
 
-       if (avg_current > 0)
+       if (current_now > 0)
                *status = POWER_SUPPLY_STATUS_CHARGING;
        else
                *status = POWER_SUPPLY_STATUS_DISCHARGING;