diff options
Diffstat (limited to 'driver/tcpm/it8xxx2.c')
-rw-r--r-- | driver/tcpm/it8xxx2.c | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/driver/tcpm/it8xxx2.c b/driver/tcpm/it8xxx2.c index dd5d1231fc..7bed654132 100644 --- a/driver/tcpm/it8xxx2.c +++ b/driver/tcpm/it8xxx2.c @@ -657,7 +657,7 @@ static int it8xxx2_tcpm_enter_low_power_mode(int port) { /* * ITE embedded TCPC SLEEP_MASK_USB_PD flag is only controlled by - * it8xxx2 driver in it8xxx2_set_pd_sleep_mask(), and do low power + * it8xxx2 driver in tc_update_pd_sleep_mask(), and do low power * mode in idle_task(). * In deep sleep mode, ITE TCPC clock is turned off, and the * timer every 5ms to exit the mode and wakeup PD task to run @@ -844,17 +844,17 @@ static int it8xxx2_tcpm_init(int port) return EC_SUCCESS; } -static void it8xxx2_set_pd_sleep_mask(int port) +__override void tc_update_pd_sleep_mask(int port) { int i; bool prevent_deep_sleep = false; /* - * Set SLEEP_MASK_USB_PD for deep sleep mode: - * 1.Enable deep sleep mode, when all ITE ports are in Unattach.SRC/SNK - * state (HOOK_DISCONNECT called) and other ports aren't pd_capable(). - * 2.Disable deep sleep mode, when one of ITE port is in Attach.SRC/SNK - * state (HOOK_CONNECT called) or one of other ports is pd_capable(). + * Check ITE embedded pd ports to set SLEEP_MASK_USB_PD: + * In tc_attached_[src, snk]_entry states, calling HOOK_CONNECT + * to enable BMC PHY, and if one of ITE pd ports BMC PHY is enable, + * then EC deep doze mode will be disabled. + * Otherwise, EC deep doze mode will be enabled. */ for (i = 0; i < CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT; ++i) { if (IT83XX_USBPD_PDGCR(i) & USBPD_REG_MASK_BMC_PHY) { @@ -864,9 +864,11 @@ static void it8xxx2_set_pd_sleep_mask(int port) } /* - * Check if any other ports have a PD port partner connected. Deep - * sleep is forbidden if any PD port partner is connected. Above, we - * only checked for the ITE ports. + * Check Other stand alone pd ports to set SLEEP_MASK_USB_PD: + * In [pe_src_send_capabilities_run, pe_snk_select_capability_entry] + * states receive [GoodCRC, SRC_CAP] from port partner, then EC deep + * doze mode will be disabled. + * Otherwise, EC deep doze mode will be enabled. */ if (!prevent_deep_sleep) { for (; i < board_get_usb_pd_port_count(); i++) @@ -884,6 +886,16 @@ static void it8xxx2_tcpm_hook_connect(void) { int port = TASK_ID_TO_PD_PORT(task_get_current()); + /* + * If it isn't ITE active port, then return. + * + * NOTE: If we don't use all the ITE pd ports on a board, then we + * need to start from port0 to use the ITE pd port. If we + * start from port1, then port1 HOOK function never works. + */ + if (port > (CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT - 1)) + return; + #ifdef CONFIG_USB_PD_TCPMV2 /* * There are five cases that hook_connect() be called by TCPMv2: @@ -906,7 +918,14 @@ static void it8xxx2_tcpm_hook_connect(void) #endif /* Enable PD PHY Tx and Rx module since type-c has connected. */ USBPD_ENABLE_BMC_PHY(port); - it8xxx2_set_pd_sleep_mask(port); + /* + * After we're in attached.[SRC, SNK] states and before we receive + * [GoodCRC of SRC_CAP, SRC_CAP] this period time, if EC goes to + * deep doze mode, the pd clock will be gated, then pd can't + * transmit and receive any messages, so we disable deep doze mode + * to make sure that pd won't miss any messages. + */ + tc_update_pd_sleep_mask(port); } DECLARE_HOOK(HOOK_USB_PD_CONNECT, it8xxx2_tcpm_hook_connect, HOOK_PRIO_DEFAULT); @@ -915,6 +934,16 @@ static void it8xxx2_tcpm_hook_disconnect(void) { int port = TASK_ID_TO_PD_PORT(task_get_current()); + /* + * If it isn't ITE active port, then return. + * + * NOTE: If we don't use all the ITE pd ports on a board, then we + * need to start from port0 to use the ITE pd port. If we + * start from port1, then port1 HOOK function never works. + */ + if (port > (CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT - 1)) + return; + if (IS_ENABLED(IT83XX_INTC_PLUG_IN_OUT_SUPPORT)) /* * Switch to detect plug in and enable detect plug in interrupt, @@ -934,7 +963,11 @@ static void it8xxx2_tcpm_hook_disconnect(void) if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP)) sop_prime_en[port] = 0; USBPD_DISABLE_BMC_PHY(port); - it8xxx2_set_pd_sleep_mask(port); + /* + * Since PD BMC PHY is off, then EC can go to deep doze mode and + * turn off pd clock. + */ + tc_update_pd_sleep_mask(port); } DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, it8xxx2_tcpm_hook_disconnect, |