From 76f1cb778934bf14ffb830a8983f339b323f8b48 Mon Sep 17 00:00:00 2001 From: Peter Marheine Date: Mon, 23 Dec 2019 15:14:07 +1100 Subject: puff: prevent AP boot when there isn't enough power The common x86 state machine does this, but the EC-controlled sequencing did not. Since trying to boot the AP without enough power will cause the system to brown out, we need to do it too. TEST=boot prevented on hardware BRANCH=none BUG=b:146515963 Change-Id: I7dbe6ab962fbe47d4d866be98d4174291c757c72 Signed-off-by: Peter Marheine Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1980104 Reviewed-by: Andrew McRae --- board/puff/board.c | 39 ++++++++++++++++++++------------------- board/puff/board.h | 1 + board/puff/usb_pd_policy.c | 3 +++ 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'board/puff') diff --git a/board/puff/board.c b/board/puff/board.c index 590085e8a5..1889ca8467 100644 --- a/board/puff/board.c +++ b/board/puff/board.c @@ -157,26 +157,17 @@ static void port_ocp_interrupt(enum gpio_signal signal) */ #define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */ /* Debounced connection state of the barrel jack */ -static int adp_connected = 1; -static void adp_state_init(void) -{ - adp_connected = !gpio_get_level(GPIO_BJ_ADP_PRESENT_L); - - /* Disable BJ power if not connected (we're on USB-C). */ - gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, !adp_connected); -} -DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_INIT_EXTPOWER); - +static int8_t adp_connected = -1; static void adp_connect_deferred(void) { struct charge_port_info pi = { 0 }; - int connected = gpio_get_level(GPIO_BJ_ADP_PRESENT_L); + int connected = !gpio_get_level(GPIO_BJ_ADP_PRESENT_L); /* Debounce */ if (connected == adp_connected) return; if (connected) { - pi.voltage = 19500; + pi.voltage = 19000; if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) /* * TODO(b:143975429) set current according to SKU. @@ -191,11 +182,6 @@ static void adp_connect_deferred(void) } charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED, DEDICATED_CHARGE_PORT, &pi); - /* - * Explicitly notifies the host that BJ is plugged or unplugged - * (when running on a type-c adapter). - */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); adp_connected = connected; } DECLARE_DEFERRED(adp_connect_deferred); @@ -203,11 +189,26 @@ DECLARE_DEFERRED(adp_connect_deferred); /* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */ void adp_connect_interrupt(enum gpio_signal signal) { - if (adp_connected == !gpio_get_level(GPIO_BJ_ADP_PRESENT_L)) - return; hook_call_deferred(&adp_connect_deferred_data, ADP_DEBOUNCE_MS * MSEC); } +static void adp_state_init(void) +{ + /* + * Initialize all charge suppliers to 0. The charge manager waits until + * all ports have reported in before doing anything. + */ + for (int i = 0; i < CHARGE_PORT_COUNT; i++) { + for (int j = 0; j < CHARGE_SUPPLIER_COUNT; j++) + charge_manager_update_charge(j, i, NULL); + } + + /* Report charge state from the barrel jack. */ + adp_connect_deferred(); +} +DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_CHARGE_MANAGER_INIT + 1); + + #include "gpio_list.h" /* Must come after other header files. */ /******************************************************************************/ diff --git a/board/puff/board.h b/board/puff/board.h index 2073738029..5b124b50cb 100644 --- a/board/puff/board.h +++ b/board/puff/board.h @@ -118,6 +118,7 @@ /* Charger */ #define CONFIG_CHARGE_MANAGER +#undef CONFIG_CHARGE_MANAGER_SAFE_MODE #define CONFIG_CHARGER_INPUT_CURRENT 512 /* Allow low-current USB charging */ /* USB type C */ diff --git a/board/puff/usb_pd_policy.c b/board/puff/usb_pd_policy.c index 13aea2afb6..dd4b8e19bd 100644 --- a/board/puff/usb_pd_policy.c +++ b/board/puff/usb_pd_policy.c @@ -65,5 +65,8 @@ int pd_snk_is_vbus_provided(int port) int board_vbus_source_enabled(int port) { + /* Ignore non-PD ports (the barrel jack). */ + if (port >= CONFIG_USB_PD_PORT_MAX_COUNT) + return 0; return ppc_is_sourcing_vbus(port); } -- cgit v1.2.1