power: supply: max17042_battery: Improve accuracy of current_now and current_avg readings

Dividing 1562500 by r_sns value usually doesn't result in an integer.

Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Sebastian Krzyszkowiak 2020-11-25 05:46:17 +01:00 коммит произвёл Sebastian Reichel
Родитель 4b0a56e692
Коммит 9e39ef1487
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -395,8 +395,8 @@ static int max17042_get_property(struct power_supply *psy,
if (ret < 0) if (ret < 0)
return ret; return ret;
val->intval = sign_extend32(data, 15); data64 = sign_extend64(data, 15) * 1562500ll;
val->intval *= 1562500 / chip->pdata->r_sns; val->intval = div_s64(data64, chip->pdata->r_sns);
} else { } else {
return -EINVAL; return -EINVAL;
} }
@ -407,8 +407,8 @@ static int max17042_get_property(struct power_supply *psy,
if (ret < 0) if (ret < 0)
return ret; return ret;
val->intval = sign_extend32(data, 15); data64 = sign_extend64(data, 15) * 1562500ll;
val->intval *= 1562500 / chip->pdata->r_sns; val->intval = div_s64(data64, chip->pdata->r_sns);
} else { } else {
return -EINVAL; return -EINVAL;
} }