From 2b36569f4e4fa7d2de62fefe77b6a1df9523f5ef Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Tue, 2 Apr 2019 11:50:16 -0700 Subject: chgstv2: Allow board to customize AP boot threshold Currently, AP boot threshold is statically set by CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON. This patch adds a callback board_set_min_power_mw_for_power_on, which allows boards to set a custom AP boot threshold. Signed-off-by: Daisuke Nojiri BUG=b/122896801 BRANCH=nami TEST=Boot Ekko. Change-Id: I9d226bab9a4b6a0f4bffaf8f75d40ad040e10a62 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1549491 Reviewed-by: YH Lin Commit-Queue: Daisuke Nojiri Tested-by: Daisuke Nojiri --- common/charge_state_v2.c | 17 +++++++++++++++-- include/charge_state_v2.h | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 9bbfdd3fc3..15070deb9e 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1510,6 +1510,17 @@ static int get_desired_input_current(enum battery_present batt_present, } } +static int min_power_mw_for_power_on; + +__attribute__((weak)) int board_set_min_power_mw_for_power_on(void) +{ +#ifdef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON + return CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON; +#else + return 0; +#endif +} + /* Main loop */ void charger_task(void *u) { @@ -1532,6 +1543,8 @@ void charger_task(void *u) charge_base = -1; #endif + min_power_mw_for_power_on = board_set_min_power_mw_for_power_on(); + /* * If system is not locked and we don't have a battery to live on, * then use max input current limit so that we can pull as much power @@ -1986,7 +1999,7 @@ int charge_prevent_power_on(int power_button_pressed) /* However, we can power on if a sufficient charger is present. */ if (prevent_power_on) { if (charge_manager_get_power_limit_uw() >= - CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000) + min_power_mw_for_power_on * 1000) prevent_power_on = 0; #if defined(CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT) && \ defined(CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC) @@ -2025,7 +2038,7 @@ int charge_prevent_power_on(int power_button_pressed) if (extpower_is_present() && battery_hw_present() == BP_NO #ifdef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON && charge_manager_get_power_limit_uw() < - CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000 + min_power_mw_for_power_on * 1000 #endif /* CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON */ ) prevent_power_on = 1; diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h index b1896ff106..88cf6357eb 100644 --- a/include/charge_state_v2.h +++ b/include/charge_state_v2.h @@ -140,4 +140,11 @@ int charge_state_limit_power(void); */ int board_check_os_boot_power(void); +/** + * Callback with which a board sets minimum power to boot AP + * + * @return Power in MW + */ +int board_set_min_power_mw_for_power_on(void); + #endif /* __CROS_EC_CHARGE_STATE_V2_H */ -- cgit v1.2.1