From b14b974ee4913c4a1d01b025fb510b9a69c84804 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Tue, 6 Feb 2018 18:58:00 -0800 Subject: tcpm/fusb302: Update VBUS supplier when VBUS level changes To enable USB charging on boards where fusb302 takes care of VBUS detection BUG=b:65446459 BRANCH=none TEST=on Scarlet rev3, verify VBUS supplier is updated based on whether VBUS is present - plug/unplug USB2 charger, boot with USB2 charger plugged. Change-Id: I50177d40b0eb0490634ad2f103306e0079633fbe Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/905401 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Nicolas Boichat --- driver/tcpm/fusb302.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'driver') diff --git a/driver/tcpm/fusb302.c b/driver/tcpm/fusb302.c index 852568f032..f51e696bb9 100644 --- a/driver/tcpm/fusb302.c +++ b/driver/tcpm/fusb302.c @@ -13,6 +13,7 @@ #include "hooks.h" #include "tcpm.h" #include "timer.h" +#include "usb_charge.h" #include "usb_pd.h" #include "usb_pd_tcpc.h" #include "util.h" @@ -396,12 +397,10 @@ static int fusb302_tcpm_init(int port) reg &= ~TCPC_REG_MASK_ALERT; #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC /* TODO(crbug.com/791109): Clean up VBUS notification. */ -#ifdef CONFIG_USB_CHARGER -#error "Use CONFIG_USB_PD_VBUS_DETECT_CHARGER instead" -#endif + /* VBUS threshold crossed (~4.0V) */ reg &= ~TCPC_REG_MASK_VBUSOK; -#endif /* CONFIG_USB_PD_VBUS_DETECT_TCPC */ +#endif tcpc_write(port, TCPC_REG_MASK, reg); reg = 0xFF; @@ -433,6 +432,18 @@ static int fusb302_tcpm_init(int port) /* TODO: Reduce power consumption */ tcpc_write(port, TCPC_REG_POWER, TCPC_REG_POWER_PWR_ALL); +#if defined(CONFIG_USB_PD_VBUS_DETECT_TCPC) && defined(CONFIG_USB_CHARGER) + /* Wait for the reference voltage to stablize */ + usleep(250); + /* + * Initialize VBUS supplier when VBUS is already present before + * init (e.g. Cold reboot with charger plugged). + */ + tcpc_read(port, TCPC_REG_STATUS0, ®); + if (reg & TCPC_REG_STATUS0_VBUSOK) + usb_charger_vbus_change(port, 1); +#endif + return 0; } @@ -878,6 +889,13 @@ void fusb302_tcpc_alert(int port) #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC if (interrupt & TCPC_REG_INTERRUPT_VBUSOK) { /* VBUS crossed threshold */ +#ifdef CONFIG_USB_CHARGER + usb_charger_vbus_change(port, + fusb302_tcpm_get_vbus_level(port)); +#else + if (!fusb302_tcpm_get_vbus_level(port)) + pd_vbus_low(port); +#endif task_wake(PD_PORT_TO_TASK_ID(port)); hook_notify(HOOK_AC_CHANGE); } -- cgit v1.2.1