diff options
-rw-r--r-- | common/battery.c | 22 | ||||
-rw-r--r-- | include/config.h | 3 |
2 files changed, 14 insertions, 11 deletions
diff --git a/common/battery.c b/common/battery.c index 4d8d962c3a..c58d0b11b7 100644 --- a/common/battery.c +++ b/common/battery.c @@ -575,11 +575,6 @@ void battery_compensate_params(struct batt_params *batt) if (*remain <= 0 || *full <= 0) return; - /* full_factor != 100 isn't supported. EC and host are not able to - * act on soc changes synchronously. */ - if (batt_host_full_factor != 100) - return; - /* full_factor is effectively disabled in powerd. */ *full = *full * batt_full_factor / 100; if (*remain > *full) @@ -587,15 +582,24 @@ void battery_compensate_params(struct batt_params *batt) /* * Powerd uses the following equation to calculate display percentage: - * charge = 100 * remain/full; - * 100 * (charge - shutdown_pct) / (full_factor - shutdown_pct); + * charge = 100 * remain / full + * display = 100 * (charge - shutdown_pct) / + * (full_factor - shutdown_pct) + * = 100 * ((100 * remain / full) - shutdown_pct) / + * (full_factor - shutdown_pct) + * = 100 * ((100 * remain) - (full * shutdown_pct)) / + * (full * (full_factor - shutdown_pct)) + * + * The unit of the following batt->display_charge is 0.1%. */ - numer = (100 * *remain - *full * batt_host_shutdown_pct) * 1000; - denom = *full * (100 - batt_host_shutdown_pct); + numer = 1000 * ((100 * *remain) - (*full * batt_host_shutdown_pct)); + denom = *full * (batt_host_full_factor - batt_host_shutdown_pct); /* Rounding (instead of truncating) */ batt->display_charge = (numer + denom / 2) / denom; if (batt->display_charge < 0) batt->display_charge = 0; + if (batt->display_charge > 1000) + batt->display_charge = 1000; } __attribute__((weak)) int get_battery_manufacturer_name(char *dest, int size) diff --git a/include/config.h b/include/config.h index c3abb4bf93..982ce4fbc4 100644 --- a/include/config.h +++ b/include/config.h @@ -503,8 +503,7 @@ #define CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE 4 /* - * Powerd's full_factor. It has to be 100(%) to get display battery percentage. - * Otherwise, display percentages will be always zero. + * Powerd's full_factor. */ #define CONFIG_BATT_HOST_FULL_FACTOR 94 |