diff options
Diffstat (limited to 'common/usbc/usb_tc_ctvpd_sm.c')
-rw-r--r-- | common/usbc/usb_tc_ctvpd_sm.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c index 46550978ed..045cca55c4 100644 --- a/common/usbc/usb_tc_ctvpd_sm.c +++ b/common/usbc/usb_tc_ctvpd_sm.c @@ -1,8 +1,9 @@ -/* Copyright 2019 The Chromium OS Authors. All rights reserved. +/* Copyright 2019 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#include "builtin/assert.h" #include "common.h" #include "console.h" #include "system.h" @@ -16,18 +17,18 @@ /* USB Type-C CTVPD module */ #ifdef CONFIG_COMMON_RUNTIME -#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) -#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args) +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args) #else /* CONFIG_COMMON_RUNTIME */ #define CPRINTF(format, args...) #define CPRINTS(format, args...) #endif /* Type-C Layer Flags */ -#define TC_FLAGS_VCONN_ON BIT(0) +#define TC_FLAGS_VCONN_ON BIT(0) -#define SUPPORT_TIMER_RESET_INIT 0 -#define SUPPORT_TIMER_RESET_REQUEST 1 +#define SUPPORT_TIMER_RESET_INIT 0 +#define SUPPORT_TIMER_RESET_REQUEST 1 #define SUPPORT_TIMER_RESET_COMPLETE 2 /** @@ -105,9 +106,8 @@ enum usb_tc_state { /* Forward declare the full list of states. This is indexed by usb_tc_state */ static const struct usb_state tc_states[]; - /* List of human readable state names for console debugging */ -__maybe_unused const char * const tc_state_names[] = { +__maybe_unused const char *const tc_state_names[] = { #ifdef CONFIG_COMMON_RUNTIME [TC_DISABLED] = "Disabled", [TC_UNATTACHED_SNK] = "Unattached.SNK", @@ -257,9 +257,9 @@ test_mockable_static void print_current_state(const int port) int pd_is_connected(int port) { return (get_state_tc(port) == TC_ATTACHED_SNK) || - (get_state_tc(port) == TC_ATTACHED_SRC) || - (get_state_tc(port) == TC_CT_ATTACHED_UNSUPPORTED) || - (get_state_tc(port) == TC_CT_ATTACHED_VPD); + (get_state_tc(port) == TC_ATTACHED_SRC) || + (get_state_tc(port) == TC_CT_ATTACHED_UNSUPPORTED) || + (get_state_tc(port) == TC_CT_ATTACHED_VPD); } bool pd_is_disconnected(int port) @@ -398,7 +398,7 @@ static void tc_unattached_snk_run(const int port) * 2) VBUS is detected */ if (vpd_is_ct_vbus_present() && - tc[port].cc_state == PD_CC_DFP_ATTACHED) { + tc[port].cc_state == PD_CC_DFP_ATTACHED) { set_state_tc(port, TC_UNATTACHED_SRC); return; } @@ -436,11 +436,11 @@ static void tc_attach_wait_snk_run(const int port) if (tc[port].host_cc_state != host_new_cc_state) { tc[port].host_cc_state = host_new_cc_state; if (host_new_cc_state == PD_CC_DFP_ATTACHED) - tc[port].host_cc_debounce = get_time().val + - PD_T_CC_DEBOUNCE; + tc[port].host_cc_debounce = + get_time().val + PD_T_CC_DEBOUNCE; else - tc[port].host_cc_debounce = get_time().val + - PD_T_PD_DEBOUNCE; + tc[port].host_cc_debounce = + get_time().val + PD_T_PD_DEBOUNCE; return; } @@ -458,7 +458,7 @@ static void tc_attach_wait_snk_run(const int port) * CC2 pins is SNK.Open for at least tPDDebounce. */ if (tc[port].host_cc_state == PD_CC_DFP_ATTACHED && - (vpd_is_vconn_present() || vpd_is_host_vbus_present())) + (vpd_is_vconn_present() || vpd_is_host_vbus_present())) set_state_tc(port, TC_ATTACHED_SNK); else if (tc[port].host_cc_state == PD_CC_NONE) set_state_tc(port, TC_UNATTACHED_SNK); @@ -551,7 +551,7 @@ static void tc_attached_snk_run(const int port) /* Check the Support Timer */ if (get_time().val > tc[port].support_timer && - !tc[port].billboard_presented) { + !tc[port].billboard_presented) { /* * Present USB Billboard Device Class interface * indicating that Charge-Through is not supported @@ -654,7 +654,7 @@ static void tc_unattached_src_run(const int port) * if Charge-Through VBUS is removed. */ if (!vpd_is_ct_vbus_present() || - get_time().val > tc[port].next_role_swap) { + get_time().val > tc[port].next_role_swap) { set_state_tc(port, TC_UNATTACHED_SNK); return; } @@ -719,7 +719,7 @@ static void tc_attach_wait_src_run(const int port) * state is on the Host-side port’s CC pin for at least tCCDebounce. */ if (tc[port].host_cc_state == PD_CC_UFP_ATTACHED && - !vpd_is_host_vbus_present()) { + !vpd_is_host_vbus_present()) { set_state_tc(port, TC_TRY_SNK); return; } @@ -847,7 +847,7 @@ static void tc_try_snk_run(const int port) * for tTryCCDebounce. */ if (tc[port].host_cc_state == PD_CC_DFP_ATTACHED && - (vpd_is_host_vbus_present() || vpd_is_vconn_present())) + (vpd_is_host_vbus_present() || vpd_is_vconn_present())) set_state_tc(port, TC_ATTACHED_SNK); else if (tc[port].host_cc_state == PD_CC_NONE) set_state_tc(port, TC_TRY_WAIT_SRC); @@ -887,7 +887,7 @@ static void tc_try_wait_src_run(const int port) if (tc[port].host_cc_state != host_new_cc_state) { tc[port].host_cc_state = host_new_cc_state; tc[port].host_cc_debounce = - get_time().val + PD_T_TRY_CC_DEBOUNCE; + get_time().val + PD_T_TRY_CC_DEBOUNCE; return; } @@ -899,7 +899,7 @@ static void tc_try_wait_src_run(const int port) * at least tTryCCDebounce. */ if (tc[port].host_cc_state == PD_CC_UFP_ATTACHED && - !vpd_is_host_vbus_present()) { + !vpd_is_host_vbus_present()) { set_state_tc(port, TC_ATTACHED_SRC); return; } @@ -988,7 +988,7 @@ static void tc_ct_try_snk_run(const int port) * Charge-Through port. */ if (tc[port].cc_state == PD_CC_DFP_ATTACHED && - vpd_is_ct_vbus_present()) { + vpd_is_ct_vbus_present()) { set_state_tc(port, TC_CT_ATTACHED_VPD); return; } @@ -1001,8 +1001,7 @@ static void tc_ct_try_snk_run(const int port) * for tDRPTryWait. */ if (tc[port].cc_state == PD_CC_NONE) { - set_state_tc(port, - TC_CT_ATTACHED_UNSUPPORTED); + set_state_tc(port, TC_CT_ATTACHED_UNSUPPORTED); return; } } @@ -1181,8 +1180,7 @@ static void tc_ct_unattached_unsupported_run(const int port) * on both the CC1 and CC2 pins. */ if (cc_is_at_least_one_rd(cc1, cc2) || cc_is_audio_acc(cc1, cc2)) { - set_state_tc(port, - TC_CT_ATTACH_WAIT_UNSUPPORTED); + set_state_tc(port, TC_CT_ATTACH_WAIT_UNSUPPORTED); return; } @@ -1343,7 +1341,7 @@ static void tc_ct_attached_vpd_entry(const int port) * pins is connected through the cable */ vpd_ct_get_cc(&cc1, &cc2); - tc[port].ct_cc = cc_is_rp(cc2) ? CT_CC2 : CT_CC1; + tc[port].ct_cc = cc_is_rp(cc2) ? CT_CC2 : CT_CC1; /* * 1. Remove or reduce any additional capacitance on the @@ -1468,10 +1466,8 @@ static void tc_ct_attach_wait_vpd_run(const int port) /* Debounce the cc state */ if (new_cc_state != tc[port].cc_state) { tc[port].cc_state = new_cc_state; - tc[port].cc_debounce = get_time().val + - PD_T_CC_DEBOUNCE; - tc[port].pd_debounce = get_time().val + - PD_T_PD_DEBOUNCE; + tc[port].cc_debounce = get_time().val + PD_T_CC_DEBOUNCE; + tc[port].pd_debounce = get_time().val + PD_T_PD_DEBOUNCE; return; } @@ -1482,7 +1478,7 @@ static void tc_ct_attach_wait_vpd_run(const int port) * port’s CC1 and CC2 pins are SNK.Open for at least * tPDDebounce. */ - if (tc[port].cc_state == PD_CC_NONE) { + if (tc[port].cc_state == PD_CC_NONE) { set_state_tc(port, TC_CT_UNATTACHED_VPD); return; } @@ -1496,8 +1492,8 @@ static void tc_ct_attach_wait_vpd_run(const int port) * least tCCDebounce and VBUS on the Charge-Through port is * detected. */ - if (tc[port].cc_state == PD_CC_DFP_ATTACHED && - vpd_is_ct_vbus_present()) { + if (tc[port].cc_state == PD_CC_DFP_ATTACHED && + vpd_is_ct_vbus_present()) { set_state_tc(port, TC_CT_ATTACHED_VPD); return; } |