From: Sebastian Krzyszkowiak Date: Mon, 6 Apr 2026 20:57:50 +0000 (-0400) Subject: power: supply: max17042_battery: Use Current register in get_status X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a733cd247eb9bda928049d72ab7ae16b9bff353;p=thirdparty%2Flinux.git power: supply: max17042_battery: Use Current register in get_status 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 Link: https://patch.msgid.link/20260406205759.493288-3-vincent.cloutier@icloud.com Signed-off-by: Sebastian Reichel --- diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 103ce1d47aa8..e896cd169a91 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -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;