From b23c2711b4fac261f604af61f9059be3ffa130f8 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Tue, 3 Apr 2018 18:50:03 -0700 Subject: usb_charger: initialize VBUS supplier at startup When using VBUS_DETECT_TCPC the charger code relied on the TCPC alert to initialize the VBUS supply, but that happens too late in board startup sequence to allow an initally plugged in USB-C power supply to be chosen as the active charging port. We can and should initialize the the supplier sooner as to prevent the charge_manager_is_seeded() check from failing thus preventing the board from choosing a charging port. BRANCH=none BUG=b:77458917 TEST=PS8751 on yorp will negotiate 20V over USB-C (which was prevent by the charge_manager not being seeded) Change-Id: I6f612c508932a90ece0036ce8310a20de02d8467 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/994707 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Divya S Sasidharan Reviewed-by: Divya S Sasidharan Reviewed-by: Aseda Aboagye Reviewed-by: Aaron Durbin Reviewed-on: https://chromium-review.googlesource.com/1236847 Tested-by: Daisuke Nojiri Commit-Queue: Daisuke Nojiri --- board/zoombini/board.c | 17 ----------------- common/usb_charger.c | 13 +++---------- common/usb_pd_protocol.c | 4 ++-- include/usb_pd.h | 7 +++++++ 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/board/zoombini/board.c b/board/zoombini/board.c index 8e11ec57dd..8f83f773d4 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -370,11 +370,6 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); static void board_init(void) { -#ifdef BOARD_ZOOMBINI - struct charge_port_info chg; - int i; -#endif /* defined(BOARD_ZOOMBINI) */ - #ifdef BOARD_ZOOMBINI /* Enable PPC interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_PPC_INT_L); @@ -387,18 +382,6 @@ static void board_init(void) gpio_enable_interrupt(GPIO_USB_C1_PD_INT_L); #ifdef BOARD_ZOOMBINI gpio_enable_interrupt(GPIO_USB_C2_PD_INT_L); - - /* Initialize VBUS suppliers. */ - for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) { - if (tcpm_get_vbus_level(i)) { - chg.voltage = 5000; - chg.current = USB_CHARGER_MIN_CURR_MA; - } else { - chg.voltage = 0; - chg.current = 0; - } - charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, i, &chg); - } #endif /* defined(BOARD_ZOOMBINI) */ } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); diff --git a/common/usb_charger.c b/common/usb_charger.c index d9d4e50fe7..554ed93b9c 100644 --- a/common/usb_charger.c +++ b/common/usb_charger.c @@ -84,7 +84,7 @@ static void usb_charger_init(void) int i; struct charge_port_info charge_none; - /* Initialize all charge suppliers to 0 */ + /* Initialize all charge suppliers */ charge_none.voltage = USB_CHARGER_VOLTAGE_MV; charge_none.current = 0; for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) { @@ -103,15 +103,8 @@ static void usb_charger_init(void) charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, i, &charge_none); - -#ifndef CONFIG_USB_PD_VBUS_DETECT_TCPC - /* - * Initialize VBUS supplier based on whether VBUS is present. - * For CONFIG_USB_PD_VBUS_DETECT_TCPC, usb_charger_vbus_change() - * will be called directly from TCPC alert. - */ - update_vbus_supplier(i, pd_snk_is_vbus_provided(i)); -#endif + /* Initialize VBUS supplier based on whether VBUS is present. */ + update_vbus_supplier(i, pd_is_vbus_present(i)); } } DECLARE_HOOK(HOOK_INIT, usb_charger_init, HOOK_PRIO_CHARGE_MANAGER_INIT + 1); diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 207ea24f6a..1f457c43ae 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -307,8 +307,9 @@ void pd_vbus_low(int port) { pd[port].flags &= ~PD_FLAGS_VBUS_NEVER_LOW; } +#endif -static inline int pd_is_vbus_present(int port) +int pd_is_vbus_present(int port) { #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC return tcpm_get_vbus_level(port); @@ -316,7 +317,6 @@ static inline int pd_is_vbus_present(int port) return pd_snk_is_vbus_provided(port); #endif } -#endif static void set_polarity(int port, int polarity) { diff --git a/include/usb_pd.h b/include/usb_pd.h index ac3d16cbc5..d9299a7f26 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1746,6 +1746,13 @@ int pd_ts_dts_plugged(int port); */ int pd_capable(int port); +/** + * Return true if vbus is present on the specified port. + * + * @param port USB-C port number + */ +int pd_is_vbus_present(int port); + /* ----- Logging ----- */ #ifdef CONFIG_USB_PD_LOGGING /** -- cgit v1.2.1