]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
power: supply: max1720x correct capacity computation
authorThomas Antoine <t.antoine@uclouvain.be>
Fri, 23 May 2025 12:51:44 +0000 (14:51 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sun, 22 Jun 2025 21:27:44 +0000 (23:27 +0200)
From the datasheet of the MAX17201/17205, the LSB should be "5.0μVh/RSENSE".
The current computation sets it at 0.5mAh=5.0μVh/10mOhm, which does not take
into account the value of rsense (which is in 10µV steps) which can be
different from 10mOhm.

Change the computation to fit the specs.

Fixes: 479b6d04964b ("power: supply: add support for MAX1720x standalone fuel gauge")
Signed-off-by: Thomas Antoine <t.antoine@uclouvain.be>
Link: https://lore.kernel.org/r/20250523-b4-gs101_max77759_fg-v4-1-b49904e35a34@uclouvain.be
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/max1720x_battery.c

index 12ecb1f40fe12dc2b63472b739d8ab5f1266bbc8..e2bd54ee3970807310fe2121af712a007d8c1fa9 100644 (file)
@@ -288,9 +288,10 @@ static int max172xx_voltage_to_ps(unsigned int reg)
        return reg * 1250;      /* in uV */
 }
 
-static int max172xx_capacity_to_ps(unsigned int reg)
+static int max172xx_capacity_to_ps(unsigned int reg,
+                                  struct max1720x_device_info *info)
 {
-       return reg * 500;       /* in uAh */
+       return reg * (500000 / info->rsense);   /* in uAh */
 }
 
 /*
@@ -394,11 +395,11 @@ static int max1720x_battery_get_property(struct power_supply *psy,
                break;
        case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
                ret = regmap_read(info->regmap, MAX172XX_DESIGN_CAP, &reg_val);
-               val->intval = max172xx_capacity_to_ps(reg_val);
+               val->intval = max172xx_capacity_to_ps(reg_val, info);
                break;
        case POWER_SUPPLY_PROP_CHARGE_AVG:
                ret = regmap_read(info->regmap, MAX172XX_REPCAP, &reg_val);
-               val->intval = max172xx_capacity_to_ps(reg_val);
+               val->intval = max172xx_capacity_to_ps(reg_val, info);
                break;
        case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
                ret = regmap_read(info->regmap, MAX172XX_TTE, &reg_val);
@@ -422,7 +423,7 @@ static int max1720x_battery_get_property(struct power_supply *psy,
                break;
        case POWER_SUPPLY_PROP_CHARGE_FULL:
                ret = regmap_read(info->regmap, MAX172XX_FULL_CAP, &reg_val);
-               val->intval = max172xx_capacity_to_ps(reg_val);
+               val->intval = max172xx_capacity_to_ps(reg_val, info);
                break;
        case POWER_SUPPLY_PROP_MODEL_NAME:
                ret = regmap_read(info->regmap, MAX172XX_DEV_NAME, &reg_val);