From 688f36f9861874d4cd89b64bcc551a5d19e157c7 Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Tue, 27 Apr 2021 16:53:11 +0800 Subject: asurada: inform usb_charger of VBUS change Since we do not use PPC for detecting VBUS in the following revision(hayato>=4), we should inform the usb_charger of VBUS status change. BUG=b:186366435 TEST=ectool usbpdpower showed disconnected if unplug adapter BRANCH=ASURADA Change-Id: Iafa37bd926a0f42d660e79a78612819848b738ae Signed-off-by: Eric Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2853088 Reviewed-by: Ting Shen Commit-Queue: Eric Yilun Lin Tested-by: Eric Yilun Lin --- baseboard/asurada/usb_pd_policy.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/baseboard/asurada/usb_pd_policy.c b/baseboard/asurada/usb_pd_policy.c index f9b8bb6cd1..1dbdd0cf40 100644 --- a/baseboard/asurada/usb_pd_policy.c +++ b/baseboard/asurada/usb_pd_policy.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ #include "adc.h" +#include "atomic.h" #include "charge_manager.h" #include "chipset.h" #include "timer.h" @@ -149,6 +150,9 @@ __override void svdm_exit_dp_mode(int port) int pd_snk_is_vbus_provided(int port) { + static int vbus_prev[CONFIG_USB_PD_PORT_MAX_COUNT]; + int vbus; + if ((IS_ENABLED(BOARD_HAYATO) && board_get_version() < 4) || (IS_ENABLED(BOARD_SPHERION) && board_get_version() < 1)) return ppc_is_vbus_present(port); @@ -157,8 +161,23 @@ int pd_snk_is_vbus_provided(int port) * (b:181203590#comment20) TODO(yllin): use * PD_VSINK_DISCONNECT_PD for non-5V case. */ - return adc_read_channel(board_get_vbus_adc(port)) >= + vbus = adc_read_channel(board_get_vbus_adc(port)) >= PD_V_SINK_DISCONNECT_MAX; + +#ifdef CONFIG_USB_CHARGER + /* + * There's no PPC to inform VBUS change for usb_charger, so inform + * the usb_charger now. + */ + if (!!(vbus_prev[port] != vbus)) + usb_charger_vbus_change(port, vbus); + + if (vbus) + atomic_or(&vbus_prev[port], 1); + else + atomic_clear(&vbus_prev[port]); +#endif + return vbus; } void pd_power_supply_reset(int port) -- cgit v1.2.1