diff options
Diffstat (limited to 'common/battery.c')
-rw-r--r-- | common/battery.c | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/common/battery.c b/common/battery.c index 117bbbb111..f048a1db91 100644 --- a/common/battery.c +++ b/common/battery.c @@ -203,8 +203,7 @@ static void print_battery_info(void) print_item_name("Cap-full:"); if (check_print_error(battery_full_charge_capacity(&value))) - ccprintf("%d mAh (%d mAh with %d %% compensation)\n", - value, value*batt_full_factor/100, batt_full_factor); + ccprintf("%d mAh\n", value); #ifdef CONFIG_CHARGER_V2 print_item_name("Display:"); @@ -239,6 +238,12 @@ static void print_battery_info(void) } ccprintf("%dh:%d\n", hour, minute); } + + print_item_name("full_factor:"); + ccprintf("0.%d\n", batt_host_full_factor); + + print_item_name("shutdown_soc:"); + ccprintf("%d %%\n", batt_host_shutdown_pct); } void print_battery_debug(void) @@ -582,22 +587,33 @@ void battery_compensate_params(struct batt_params *batt) if (*remain <= 0 || *full <= 0) return; - /* full_factor is effectively disabled in powerd. */ - *full = *full * batt_full_factor / 100; + /* Some batteries don't update full capacity as often. */ + if (!IS_ENABLED(CONFIG_BATTERY_EXPORT_DISPLAY_SOC)) + /* full_factor is effectively disabled in powerd. */ + *full = *full * batt_full_factor / 100; if (*remain > *full) *remain = *full; /* - * Powerd uses the following equation to calculate display percentage: - * 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)) + * EC calculates the display SoC like how Powerd used to do. Powerd + * reads the display SoC from the EC. This design allows the system to + * behave consistently on a single SoC value across all power states. + * + * Display SoC is computed as follows: * - * The unit of the following batt->display_charge is 0.1%. + * actual_soc = 100 * remain / full + * + * actual_soc - shutdown_pct + * display_soc = --------------------------- x 1000 + * full_factor - shutdown_pct + * + * (100 * remain / full) - shutdown_pct + * = ------------------------------------ x 1000 + * full_factor - shutdown_pct + * + * 100 x remain - full x shutdown_pct + * = ----------------------------------- x 1000 + * full x (full_factor - shutdown_pct) */ numer = 1000 * ((100 * *remain) - (*full * batt_host_shutdown_pct)); denom = *full * (batt_host_full_factor - batt_host_shutdown_pct); @@ -609,6 +625,21 @@ void battery_compensate_params(struct batt_params *batt) batt->display_charge = 1000; } +#ifdef CONFIG_BATTERY_EXPORT_DISPLAY_SOC +static int battery_display_soc(struct host_cmd_handler_args *args) +{ + struct ec_response_display_soc *r = args->response; + + r->display_soc = charge_get_display_charge(); + r->full_factor = batt_host_full_factor * 10; + r->shutdown_soc = batt_host_shutdown_pct * 10; + args->response_size = sizeof(*r); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_DISPLAY_SOC, battery_display_soc, EC_VER_MASK(0)); +#endif + __overridable void board_battery_compensate_params(struct batt_params *batt) { } |