Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>

authored by

Thomas Antoine and committed by
Sebastian Reichel
58ae0361 4deeea4b

+6 -5
+6 -5
drivers/power/supply/max1720x_battery.c
··· 288 288 return reg * 1250; /* in uV */ 289 289 } 290 290 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) 292 293 { 293 - return reg * 500; /* in uAh */ 294 + return reg * (500000 / info->rsense); /* in uAh */ 294 295 } 295 296 296 297 /* ··· 395 394 break; 396 395 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 397 396 ret = regmap_read(info->regmap, MAX172XX_DESIGN_CAP, &reg_val); 398 - val->intval = max172xx_capacity_to_ps(reg_val); 397 + val->intval = max172xx_capacity_to_ps(reg_val, info); 399 398 break; 400 399 case POWER_SUPPLY_PROP_CHARGE_AVG: 401 400 ret = regmap_read(info->regmap, MAX172XX_REPCAP, &reg_val); 402 - val->intval = max172xx_capacity_to_ps(reg_val); 401 + val->intval = max172xx_capacity_to_ps(reg_val, info); 403 402 break; 404 403 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 405 404 ret = regmap_read(info->regmap, MAX172XX_TTE, &reg_val); ··· 423 422 break; 424 423 case POWER_SUPPLY_PROP_CHARGE_FULL: 425 424 ret = regmap_read(info->regmap, MAX172XX_FULL_CAP, &reg_val); 426 - val->intval = max172xx_capacity_to_ps(reg_val); 425 + val->intval = max172xx_capacity_to_ps(reg_val, info); 427 426 break; 428 427 case POWER_SUPPLY_PROP_MODEL_NAME: 429 428 ret = regmap_read(info->regmap, MAX172XX_DEV_NAME, &reg_val);