diff options
| author | Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> | 2026-04-06 16:57:50 -0400 |
|---|---|---|
| committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2026-06-03 21:29:39 +0200 |
| commit | 0a733cd247eb9bda928049d72ab7ae16b9bff353 (patch) | |
| tree | c4b17e9b8633b158e1478a3739d12051bbbce683 | |
| parent | 63f2279aa1eca55c0f6403f488739f1ff54d8564 (diff) | |
| download | linux-0a733cd247eb9bda928049d72ab7ae16b9bff353.tar.gz linux-0a733cd247eb9bda928049d72ab7ae16b9bff353.zip | |
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 <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>
| -rw-r--r-- | drivers/power/supply/max17042_battery.c | 9 |
1 files changed, 4 insertions, 5 deletions
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; |
