diff options
author | Philip Chen <philipchen@google.com> | 2018-02-06 18:58:00 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-08 14:04:40 -0800 |
commit | b14b974ee4913c4a1d01b025fb510b9a69c84804 (patch) | |
tree | 54a14c431a08340d6adcf5854b6cf7d188435eeb | |
parent | 700523f49753637ebe744303f0e611c999fcfd8d (diff) | |
download | chrome-ec-b14b974ee4913c4a1d01b025fb510b9a69c84804.tar.gz |
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 <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905401
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | driver/tcpm/fusb302.c | 26 |
1 files changed, 22 insertions, 4 deletions
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); } |