diff options
author | Duncan Laurie <dlaurie@google.com> | 2017-07-28 17:13:26 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-31 01:53:09 +0000 |
commit | bd018841f6f2856c949dcf9b6dd462872cd18d7f (patch) | |
tree | 245d6874e54040b49d7cd3e166528f3939b513e9 | |
parent | bd67306369e6141fefaf8d8a6ea814a03d02f88d (diff) | |
download | chrome-ec-bd018841f6f2856c949dcf9b6dd462872cd18d7f.tar.gz |
eve: Move board level TCPC init to happen in pd_task init
When the board level TCPC run as an init hook it will frequently
lead to an EC reset when we are trying to recovery a disconnected
battery, potentially even a reboot loop with the most unlucky
timing.
If we instead call it from the pd_task before tcpc_init is called
then the board init hook can stall the pd_task init until the
battery is out of disconnect mode, or giving up after 2 seconds
in case the battery never seems to recover.
This accomplishes two goals: ensure the PD chips are not reset until
the battery is out of disconnect and delay start of the pd_task
(and PD negotiation) until the battery is out of disconnect state.
With this change I never see an EC reset when recovering from
a disconnected battery state.
BUG=b:63957122
BRANCH=eve
TEST=manual testing on Eve with 50+ battery disconnect and battery
cutoff cycles to ensure it never triggers an unexpected EC reset.
Change-Id: Ie1604e82916ea203a32cbdde98f6697e344bba4c
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Reviewed-on: https://chromium-review.googlesource.com/592716
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2320248
Commit-Queue: Patryk Duda <pdk@semihalf.com>
Tested-by: Patryk Duda <pdk@semihalf.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | board/eve/board.c | 15 | ||||
-rw-r--r-- | board/eve/board.h | 2 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 5 | ||||
-rw-r--r-- | include/config.h | 3 |
4 files changed, 23 insertions, 2 deletions
diff --git a/board/eve/board.c b/board/eve/board.c index 5e9e3e700e..c95eec9c57 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -300,6 +300,18 @@ void board_reset_pd_mcu(void) void board_tcpc_init(void) { + int count = 0; + int port; + + /* Wait for disconnected battery to wake up */ + while (battery_hw_present() == BP_YES && + battery_is_present() == BP_NO) { + usleep(100 * MSEC); + /* Give up waiting after 2 seconds */ + if (++count > 20) + break; + } + /* Only reset TCPC if not sysjump */ if (!system_jumped_late()) board_reset_pd_mcu(); @@ -318,10 +330,9 @@ void board_tcpc_init(void) * Initialize HPD to low; after sysjump SOC needs to see * HPD pulse to enable video path */ - for (int port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) + for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) usb_mux_hpd_update(port, 0, 0); } -DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C+1); uint16_t tcpc_get_alert_status(void) { diff --git a/board/eve/board.h b/board/eve/board.h index 086ada0de7..8a9a9f2faa 100644 --- a/board/eve/board.h +++ b/board/eve/board.h @@ -163,6 +163,7 @@ #define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 #define CONFIG_USB_PD_PORT_MAX_COUNT 2 #define CONFIG_USB_PD_VBUS_DETECT_CHARGER +#define CONFIG_USB_PD_TCPC_BOARD_INIT #define CONFIG_USB_PD_TCPC_LOW_POWER #define CONFIG_USB_PD_TCPM_MUX #define CONFIG_USB_PD_TCPM_ANX3429 @@ -286,6 +287,7 @@ enum adc_channel { int board_get_version(void); void board_reset_pd_mcu(void); void board_set_tcpc_power_mode(int port, int mode); +void board_tcpc_init(void); void led_register_double_tap(void); void board_update_ac_status(void); diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 71343f1334..63c300b9ca 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2955,6 +2955,11 @@ void pd_task(void *u) set_vconn(port, 0); #endif +#ifdef CONFIG_USB_PD_TCPC_BOARD_INIT + /* Board specific TCPC init */ + board_tcpc_init(); +#endif + /* Initialize TCPM driver and wait for TCPC to be ready */ res = reset_device_and_notify(port); invalidate_last_message_id(port); diff --git a/include/config.h b/include/config.h index 1a6f1767a9..ea17b81bb7 100644 --- a/include/config.h +++ b/include/config.h @@ -3978,6 +3978,9 @@ /* Use TCPC module (type-C port controller) */ #undef CONFIG_USB_PD_TCPC +/* Board provides specific TCPC init function */ +#undef CONFIG_USB_PD_TCPC_BOARD_INIT + /* Enable TCPC to enter low power mode */ #undef CONFIG_USB_PD_TCPC_LOW_POWER |