Skip to content

Commit 58ae036

Browse files
Thomas Antoinesre
authored andcommitted
power: supply: max1720x correct capacity computation
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: 479b6d0 ("power: supply: add support for MAX1720x standalone fuel gauge") Signed-off-by: Thomas Antoine <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 4deeea4 commit 58ae036

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/power/supply/max1720x_battery.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ static int max172xx_voltage_to_ps(unsigned int reg)
288288
return reg * 1250; /* in uV */
289289
}
290290

291-
static int max172xx_capacity_to_ps(unsigned int reg)
291+
static int max172xx_capacity_to_ps(unsigned int reg,
292+
struct max1720x_device_info *info)
292293
{
293-
return reg * 500; /* in uAh */
294+
return reg * (500000 / info->rsense); /* in uAh */
294295
}
295296

296297
/*
@@ -394,11 +395,11 @@ static int max1720x_battery_get_property(struct power_supply *psy,
394395
break;
395396
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
396397
ret = regmap_read(info->regmap, MAX172XX_DESIGN_CAP, &reg_val);
397-
val->intval = max172xx_capacity_to_ps(reg_val);
398+
val->intval = max172xx_capacity_to_ps(reg_val, info);
398399
break;
399400
case POWER_SUPPLY_PROP_CHARGE_AVG:
400401
ret = regmap_read(info->regmap, MAX172XX_REPCAP, &reg_val);
401-
val->intval = max172xx_capacity_to_ps(reg_val);
402+
val->intval = max172xx_capacity_to_ps(reg_val, info);
402403
break;
403404
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
404405
ret = regmap_read(info->regmap, MAX172XX_TTE, &reg_val);
@@ -422,7 +423,7 @@ static int max1720x_battery_get_property(struct power_supply *psy,
422423
break;
423424
case POWER_SUPPLY_PROP_CHARGE_FULL:
424425
ret = regmap_read(info->regmap, MAX172XX_FULL_CAP, &reg_val);
425-
val->intval = max172xx_capacity_to_ps(reg_val);
426+
val->intval = max172xx_capacity_to_ps(reg_val, info);
426427
break;
427428
case POWER_SUPPLY_PROP_MODEL_NAME:
428429
ret = regmap_read(info->regmap, MAX172XX_DEV_NAME, &reg_val);

0 commit comments

Comments
 (0)