diff options
| author | Linux Build Service Account <lnxbuild@quicinc.com> | 2017-11-05 22:32:49 -0800 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2017-11-05 22:32:49 -0800 |
| commit | b6f12218b557240e6aaa77a416e3d3c9040c72f7 (patch) | |
| tree | bf47979b4471ecd5e7b15714bbc6384b7937955d | |
| parent | 697888e330365e900c3144c1d29fc874a2ced244 (diff) | |
| parent | 9445c8845856acdb71eb2fe180dfab00ac91a783 (diff) | |
Merge "power: qpnp-fg-gen3: Fine tune the monotonic SOC calculation"
| -rw-r--r-- | drivers/power/supply/qcom/qpnp-fg-gen3.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/power/supply/qcom/qpnp-fg-gen3.c b/drivers/power/supply/qcom/qpnp-fg-gen3.c index e5f8ef5bdea3..491dda6ff7e8 100644 --- a/drivers/power/supply/qcom/qpnp-fg-gen3.c +++ b/drivers/power/supply/qcom/qpnp-fg-gen3.c @@ -762,7 +762,19 @@ static int fg_get_msoc(struct fg_chip *chip, int *msoc) if (rc < 0) return rc; - *msoc = DIV_ROUND_CLOSEST(*msoc * FULL_CAPACITY, FULL_SOC_RAW); + /* + * To have better endpoints for 0 and 100, it is good to tune the + * calculation discarding values 0 and 255 while rounding off. Rest + * of the values 1-254 will be scaled to 1-99. DIV_ROUND_UP will not + * be suitable here as it rounds up any value higher than 252 to 100. + */ + if (*msoc == FULL_SOC_RAW) + *msoc = 100; + else if (*msoc == 0) + *msoc = 0; + else + *msoc = DIV_ROUND_CLOSEST((*msoc - 1) * (FULL_CAPACITY - 2), + FULL_SOC_RAW - 2) + 1; return 0; } |
