From 193b7fcffe40413fd70e222ee52106baf0d844aa Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Tue, 22 Jun 2021 21:24:06 -0700 Subject: chgstv2: Unify power-on and shutdown battery thresholds Currently, power-on battery SoC and shutdown battery SoC are independently configured by each board. This patch will unify the setting as follows: CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 2 (don't boot if soc < 2%) CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2 (shutdown if soc <= 2%) BATTERY_LEVEL_SHUTDOWN = 3 (shutdown if soc < 3%) CONFIG_BATTERY_EXPORT_DISPLAY_SOC = Y (removed) CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC = 1 This allows us to show the low battery alert whenever we can because EC doesn't inhibit power-on even if it knows the host would immediately shut down. With CONFIG_BATTERY_EXPORT_DISPLAY_SOC, boards will start using the CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2% as the low battery threshold (and the SoC will be agreed between the EC and Powerd). Boards with CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 1 will keep the same threshold. This is for avoiding degrading the UX by increasing the power-on threshold (even though a question that 1% may not be enough for soft sync to finish consistently remains to be answered). Boards with CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON > 2 will have a lower threshold but we think 2% is enough to finish the software sync. A lower threshold also improves the UX by showing the low battery alert in the situation where otherwise the system would leave the user uninformed by not responding to a power button press. BUG=b:191837893 BRANCH=None TEST=buildall Change-Id: If6ff733bc181f929561a3fffb8a84e760668ce37 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2981468 Reviewed-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3872712 --- include/config.h | 63 +++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) (limited to 'include/config.h') diff --git a/include/config.h b/include/config.h index faa1f5ed3c..2a1e5f5759 100644 --- a/include/config.h +++ b/include/config.h @@ -492,60 +492,43 @@ #undef CONFIG_BATTERY_MEASURE_IMBALANCE /* - * If remaining capacity is x% of full capacity, remaining capacity is set - * equal to full capacity. - * * Some batteries don't update full capacity timely or don't update it at all. * On such systems, compensation is required to guarantee remaining_capacity * will be equal to full_capacity eventually. This used to be done in ACPI. * - * When CONFIG_BATTERY_EXPORT_DISPLAY_SOC is enabled, CONFIG_BATT_FULL_FACTOR - * has no effect. Also CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE is used by Powerd - * as the threshold for low battery shutdown. For example, if we have: + * Powerd uses CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE as the threshold for low + * battery shutdown. + * + * We want to show the low battery alert whenever we can. Thus, we make EC not + * inhibit power-on even if it knows the host would immediately shut down. To + * get that behavior, we need: + * + * MIN_BAT_PCT_FOR_POWER_ON < HOST_SHUTDOWN_PER = BATTERY_LEVEL_SHUTDOWN * - * CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 3 - * CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2, - * BATTERY_LEVEL_SHUTDOWN = 1 + * Thus, we set them as follows by default: * - * the battery range is divided as follows (assuming system is powered only by - * internal battery): + * CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 2 (don't boot if soc < 2%) + * CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2 (shutdown if soc <= 2%) + * BATTERY_LEVEL_SHUTDOWN = 3 (shutdown if soc < 3%) * - * 0% ------------------- 1% ------------------- 2% ------------------- 3% - * EC refuses to boot -> - * Powerd shuts down system -> - * EC shuts down system -> + * This produces the following behavior: + * + * - If soc = 1%, system doesn't boot. User wouldn't know why. + * - If soc = 2%, system boots. Alert is shown. System immediately shuts down. + * - If battery discharges to 2% while the system is running, system shuts down. + * If that happens while a user is away, they can press the power button to + * learn what happened. */ -#define CONFIG_BATT_FULL_FACTOR 98 -#define CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE 4 +#define CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE 2 /* shutdown if soc <= 2% */ /* * Powerd's full_factor. The value comes from: * src/platform2/power_manager/default_prefs/power_supply_full_factor * - * When CONFIG_BATTERY_EXPORT_DISPLAY_SOC is enabled, this value is exported - * to the host (i.e. Powerd). It's used to calculate the ETA for full charge. + * This value is used by the host to calculate the ETA for full charge. */ #define CONFIG_BATT_HOST_FULL_FACTOR 97 -/* - * This option enables EC to be the origin of the display SoC and allows the - * host (i.e. Powerd) to retrieve it through EC_CMD_DISPLAY_SOC. - * - * The display SoC is computed from the remaining capacity, the last full - * charge, CONFIG_BATT_FULL_FACTOR, CONFIG_BATT_HOST_FULL_FACTOR, and - * CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE. - * - * If this option is disabled, the EC and the host will individually compute - * the display SoC, which may result in inconsistent behaviors since the numbers - * do not necessarily match. As such, this option is going to be enabled by - * default and the old behavior (#undef CONFIG_BATTERY_EXPORT_DISPLAY_SOC) will - * be deprecated. - * - * TODO: Define CONFIG_BATTERY_EXPORT_DISPLAY_SOC by default and remove - * CONFIG_BATTERY_EXPORT_DISPLAY_SOC and CONFIG_BATT_FULL_FACTOR. - */ -#undef CONFIG_BATTERY_EXPORT_DISPLAY_SOC - /* * Expose some data when it is needed. * For example, battery disconnect state @@ -866,8 +849,8 @@ * analog signaling. If the AP requires greater than 15W to boot, then see * CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW. */ -#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON -#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC +#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 /* Don't boot if soc < 2% */ +#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC 1 /* Default: 15000 */ #undef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON /* Default: Disabled */ -- cgit v1.2.1