power: supply: max17042: consider task period (max77759)

Several (register) values reported by the fuel gauge depend on its
internal task period and it needs to be taken into account when
calculating results. All relevant example formulas in the data sheet
assume the default task period (of 5760) and final results need to be
adjusted based on the task period in effect.

Update the code as and where necessary.

Reviewed-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: André Draszik <andre.draszik@linaro.org>
Link: https://patch.msgid.link/20260302-max77759-fg-v3-10-3c5f01dbda23@linaro.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
André Draszik
2026-03-02 13:32:09 +00:00
committed by Sebastian Reichel
parent 2864fb6aa9
commit 83a86e27c3
2 changed files with 21 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ struct max17042_chip {
struct work_struct work;
int init_complete;
int irq;
int task_period;
};
static enum power_supply_property max17042_battery_props[] = {
@@ -331,6 +332,8 @@ static int max17042_get_property(struct power_supply *psy,
return ret;
data64 = data * 5000000ll;
data64 *= chip->task_period;
do_div(data64, MAX17042_DEFAULT_TASK_PERIOD);
do_div(data64, chip->pdata->r_sns);
val->intval = data64;
break;
@@ -340,6 +343,8 @@ static int max17042_get_property(struct power_supply *psy,
return ret;
data64 = data * 5000000ll;
data64 *= chip->task_period;
do_div(data64, MAX17042_DEFAULT_TASK_PERIOD);
do_div(data64, chip->pdata->r_sns);
val->intval = data64;
break;
@@ -349,6 +354,8 @@ static int max17042_get_property(struct power_supply *psy,
return ret;
data64 = data * 5000000ll;
data64 *= chip->task_period;
do_div(data64, MAX17042_DEFAULT_TASK_PERIOD);
do_div(data64, chip->pdata->r_sns);
val->intval = data64;
break;
@@ -358,6 +365,8 @@ static int max17042_get_property(struct power_supply *psy,
return ret;
data64 = sign_extend64(data, 15) * 5000000ll;
data64 *= chip->task_period;
data64 = div_s64(data64, MAX17042_DEFAULT_TASK_PERIOD);
val->intval = div_s64(data64, chip->pdata->r_sns);
break;
case POWER_SUPPLY_PROP_TEMP:
@@ -1142,6 +1151,17 @@ static int max17042_probe(struct i2c_client *client, struct device *dev, int irq
regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007);
}
chip->task_period = MAX17042_DEFAULT_TASK_PERIOD;
if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX77759) {
ret = regmap_read(chip->regmap, MAX17042_TaskPeriod, &val);
if (ret)
return dev_err_probe(dev, ret,
"failed to read task period\n");
chip->task_period = val;
}
dev_dbg(dev, "task period: %#.4x (%d)\n", chip->task_period,
chip->task_period);
chip->battery = devm_power_supply_register(dev, max17042_desc,
&psy_cfg);
if (IS_ERR(chip->battery))