From 863d0b81fd658e1becb5e1cadd4169189ebdc872 Mon Sep 17 00:00:00 2001 From: Ben Lok Date: Thu, 31 Dec 2015 20:31:57 +0800 Subject: oak: pd: move power change notification to function board_set_charge_limit. if CONFIG_USB_PD_TCPM_VBUS is enabled, a race condition may happen: In function pd_set_input_current_limit() and typec_set_input_current_limit(), EC may notify AP power change event before PD send the up-to-date POWER_STATUS TCPC alert to EC. It will cause the AP get the stale power status. Move the power change event notification to board_set_charge_limit(), it will be called after EC receives POWER_STATUS TCPC alert, and sending power change event notification only if the "charge limit" or "charge port" or supplier is changed. BUG=chrome-os-partner:48801 BRANCH=none TEST=make buildall -j; Tested on Oak by plug/unplug AC adapter to type-C ports and verify the UI battery icon shows the correct status instantly. Change-Id: I52f0e268fdebc45e609d843847540ae48cd0a9eb Signed-off-by: Ben Lok Reviewed-on: https://chromium-review.googlesource.com/320066 Reviewed-by: Rong Chang --- board/oak/board.c | 1 + board/oak/usb_pd_policy.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/board/oak/board.c b/board/oak/board.c index 1b4141b4f7..065a7f62ea 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -269,6 +269,7 @@ void board_set_charge_limit(int charge_ma) { charge_set_input_current_limit(MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT)); + pd_send_host_event(PD_EVENT_POWER_CHANGE); } /** diff --git a/board/oak/usb_pd_policy.c b/board/oak/usb_pd_policy.c index 9a37c8b205..38db163b58 100644 --- a/board/oak/usb_pd_policy.c +++ b/board/oak/usb_pd_policy.c @@ -81,8 +81,12 @@ void pd_set_input_current_limit(int port, uint32_t max_ma, charge.voltage = supply_voltage; charge_manager_update_charge(CHARGE_SUPPLIER_PD, port, &charge); #endif - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); + /* + * move power info change notification to board_set_charge_limit(), + * board_set_charge_limit() will be executed in call stack of + * charge_manager_update_charge() if the "charge limit" or "charge port" + * or supplier if is changed. + */ } void typec_set_input_current_limit(int port, uint32_t max_ma, @@ -94,11 +98,15 @@ void typec_set_input_current_limit(int port, uint32_t max_ma, charge.voltage = supply_voltage; charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, port, &charge); #endif - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); + /* + * move power info change notification to board_set_charge_limit(), + * board_set_charge_limit() will be executed in call stack of + * charge_manager_update_charge() if the "charge limit" or "charge port" + * or supplier if is changed. + */ } + int pd_board_checks(void) { #if BOARD_REV <= OAK_REV3 -- cgit v1.2.1