From c5e4ff3605152c0f0234c45da7812795f6e35be7 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 2 Sep 2014 13:06:04 -0700 Subject: pd: Initialize dual role state based on chipset state When we do sysjump, the chipset might be in any of S0/S3/S5 states, and thus we cannot just initialize the dual role state to its default state. Instead, let's look at the chipset state and set the appropriate dual role state. BUG=chrome-os-partner:31724 TEST=On Ryu, do a sysjump and check dual role state. BRANCH=factory-ryu-6212.B Change-Id: I67abcc7fb1357d11498973a831ab8b32dad670ce Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/215866 Reviewed-by: Alec Berg Reviewed-by: Todd Broch (cherry picked from commit 386ada84e9464b0c3ec76cf64129e40a2f0c9131) Reviewed-on: https://chromium-review.googlesource.com/216258 --- common/usb_pd_protocol.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 7952f12589..c2735863f1 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -5,6 +5,7 @@ #include "adc.h" #include "board.h" +#include "chipset.h" #include "common.h" #include "console.h" #include "crc.h" @@ -1499,6 +1500,19 @@ static void dual_role_force_sink(void) CPRINTS("chipset -> S5, force dual-role port to sink"); } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, dual_role_force_sink, HOOK_PRIO_DEFAULT); + +#ifdef HAS_TASK_CHIPSET +static void dual_role_init(void) +{ + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + dual_role_force_sink(); + else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) + dual_role_off(); + else /* CHIPSET_STATE_ON */ + dual_role_on(); +} +DECLARE_HOOK(HOOK_INIT, dual_role_init, HOOK_PRIO_DEFAULT); +#endif /* HAS_TASK_CHIPSET */ #endif /* CONFIG_USB_PD_DUAL_ROLE */ #ifdef CONFIG_COMMON_RUNTIME -- cgit v1.2.1