diff options
author | Denis Brockus <dbrockus@google.com> | 2020-11-02 15:34:10 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-05 18:19:19 +0000 |
commit | cb5058d798c53a8cb46c7cf67c2cf77f76670f3a (patch) | |
tree | fc06ef12a999a5df70945a52e1ed3eb744ec9424 /common/usbc | |
parent | 65f7bd8137a8e8754f26146387a88f400b3f5b31 (diff) | |
download | chrome-ec-cb5058d798c53a8cb46c7cf67c2cf77f76670f3a.tar.gz |
tcpmv2: ifdef cleanup with IS_ENABLED
Remove as many #if preprocessor statements as possible
without allowing the code to grow when it is compiled.
Verified against the sizes built on current ToT and
this CL on that ToT
~/trunk/src/platform/ec $ make newsizes
Compared 699 of 699 files.
File sizes are unchanged.
BUG=b:172208011
BRANCH=none
TEST=verify TCPMv2 functionality
Signed-off-by: Denis Brockus <dbrockus@google.com>
Change-Id: Ib7d6a41b418f0683d3f7a14236b377073f346010
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2515279
Tested-by: Denis Brockus <dbrockus@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/usbc')
-rw-r--r-- | common/usbc/usb_pe_ctvpd_sm.c | 8 | ||||
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 126 | ||||
-rw-r--r-- | common/usbc/usb_prl_sm.c | 110 | ||||
-rw-r--r-- | common/usbc/usb_tc_ctvpd_sm.c | 6 | ||||
-rw-r--r-- | common/usbc/usb_tc_drp_acc_trysrc_sm.c | 349 | ||||
-rw-r--r-- | common/usbc/usb_tc_vpd_sm.c | 6 |
6 files changed, 312 insertions, 293 deletions
diff --git a/common/usbc/usb_pe_ctvpd_sm.c b/common/usbc/usb_pe_ctvpd_sm.c index ee5c10aca1..aec9e80c93 100644 --- a/common/usbc/usb_pe_ctvpd_sm.c +++ b/common/usbc/usb_pe_ctvpd_sm.c @@ -190,12 +190,8 @@ static void pe_request_run(const int port) VPD_MAX_VBUS_20V, VPD_VBUS_IMP(VPD_VBUS_IMPEDANCE), VPD_GND_IMP(VPD_GND_IMPEDANCE), -#ifdef CONFIG_USB_CTVPD - VPD_CTS_SUPPORTED -#else - VPD_CTS_NOT_SUPPORTED -#endif - ); + IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_CTS_SUPPORTED + : VPD_CTS_NOT_SUPPORTED); /* 20 bytes, 5 data objects */ tx_emsg[port].len = 20; diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 139e8454b0..691bf44b68 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -345,9 +345,8 @@ static const struct usb_state pe_states[]; #define USB_PD_DEBUG_LABELS #endif -#ifdef USB_PD_DEBUG_LABELS /* List of human readable state names for console debugging */ -static const char * const pe_state_names[] = { +__maybe_unused static const char * const pe_state_names[] = { /* Super States */ #ifdef CONFIG_USB_PD_REV30 [PE_PRS_FRS_SHARED] = "SS:PE_PRS_FRS_SHARED", @@ -433,13 +432,6 @@ static const char * const pe_state_names[] = { #endif #endif /* CONFIG_USB_PD_REV30 */ }; -#else -/* - * Here and below, ensure that invalid states don't link properly. This lets us - * use guard code with IS_ENABLED instead of ifdefs and still save flash space. - */ -STATIC_IF(USB_PD_DEBUG_LABELS) const char **pe_state_names; -#endif #ifndef CONFIG_USBC_VCONN GEN_NOT_SUPPORTED(PE_VCS_EVALUATE_SWAP); @@ -1435,16 +1427,19 @@ static void pe_send_request_msg(int port) static void pe_update_pdo_flags(int port, uint32_t pdo) { -#ifdef CONFIG_CHARGE_MANAGER -#ifdef CONFIG_USB_PD_ALT_MODE_DFP - int charge_allowlisted = - (pd_get_power_role(port) == PD_ROLE_SINK && - pd_charge_from_device(pd_get_identity_vid(port), - pd_get_identity_pid(port))); -#else - const int charge_allowlisted = 0; -#endif -#endif + int charge_allowlisted; + + if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) { + if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { + charge_allowlisted = + (pd_get_power_role(port) == PD_ROLE_SINK && + pd_charge_from_device( + pd_get_identity_vid(port), + pd_get_identity_pid(port))); + } else { + charge_allowlisted = 0; + } + } /* can only parse PDO flags if type is fixed */ if ((pdo & PDO_TYPE_MASK) != PDO_TYPE_FIXED) @@ -1473,22 +1468,23 @@ static void pe_update_pdo_flags(int port, uint32_t pdo) else tc_partner_dr_data(port, 0); -#ifdef CONFIG_CHARGE_MANAGER /* * Treat device as a dedicated charger (meaning we should charge * from it) if it does not support power swap, or if it is unconstrained * power, or if we are a sink and the device identity matches a * charging allow-list. */ - if (!(pdo & PDO_FIXED_DUAL_ROLE) || (pdo & PDO_FIXED_UNCONSTRAINED) || - charge_allowlisted) { - PE_CLR_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE); - charge_manager_update_dualrole(port, CAP_DEDICATED); - } else { - PE_SET_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE); - charge_manager_update_dualrole(port, CAP_DUALROLE); + if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) { + if (!(pdo & PDO_FIXED_DUAL_ROLE) || + (pdo & PDO_FIXED_UNCONSTRAINED) || + charge_allowlisted) { + PE_CLR_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE); + charge_manager_update_dualrole(port, CAP_DEDICATED); + } else { + PE_SET_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE); + charge_manager_update_dualrole(port, CAP_DUALROLE); + } } -#endif } void pd_request_power_swap(int port) @@ -1523,7 +1519,6 @@ static bool port_try_vconn_swap(int port) return false; } -#ifdef CONFIG_USB_PD_ALT_MODE_DFP /* * Run discovery at our leisure from PE_SNK_Ready or PE_SRC_Ready, after * attempting to get into the desired default policy of DFP/Vconn source @@ -1531,8 +1526,11 @@ static bool port_try_vconn_swap(int port) * Return indicates whether set_state was called, in which case the calling * function should return as well. */ -static bool pe_attempt_port_discovery(int port) +__maybe_unused static bool pe_attempt_port_discovery(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); + /* * DONE set once modal entry is successful, discovery completes, or * discovery results in a NAK @@ -1615,7 +1613,6 @@ static bool pe_attempt_port_discovery(int port) return false; } -#endif bool pd_setup_vdm_request(int port, enum tcpm_transmit_type tx_type, uint32_t *vdm, uint32_t vdo_cnt) @@ -3480,7 +3477,6 @@ static void pe_send_not_supported_run(int port) } } -#if defined(CONFIG_USB_PD_REV30) && !defined(CONFIG_USB_PD_EXTENDED_MESSAGES) /** * PE_SRC_Chunk_Received and PE_SNK_Chunk_Received * @@ -3495,19 +3491,26 @@ static void pe_send_not_supported_run(int port) * 6.6.18.1 ChunkingNotSupportedTimer * 8.3.3.6 Not Supported Message State Diagrams */ -static void pe_chunk_received_entry(int port) +__maybe_unused static void pe_chunk_received_entry(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_REV30) || + IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + assert(0); + print_current_state(port); pe[port].chunking_not_supported_timer = get_time().val + PD_T_CHUNKING_NOT_SUPPORTED; } -static void pe_chunk_received_run(int port) +__maybe_unused static void pe_chunk_received_run(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_REV30) || + IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + assert(0); + if (get_time().val > pe[port].chunking_not_supported_timer) set_state_pe(port, PE_SEND_NOT_SUPPORTED); } -#endif /** * PE_SRC_Ping @@ -4387,12 +4390,14 @@ static void pe_prs_snk_src_send_swap_run(int port) } } -#ifdef CONFIG_USB_PD_REV30 /** * PE_FRS_SNK_SRC_Start_AMS */ -static void pe_frs_snk_src_start_ams_entry(int port) +__maybe_unused static void pe_frs_snk_src_start_ams_entry(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_REV30)) + assert(0); + print_current_state(port); /* Contract is invalid now */ @@ -4409,8 +4414,11 @@ static void pe_frs_snk_src_start_ams_entry(int port) /** * PE_PRS_FRS_SHARED */ -static void pe_prs_frs_shared_entry(int port) +__maybe_unused static void pe_prs_frs_shared_entry(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_REV30)) + assert(0); + /* * Shared PRS/FRS code, assume PRS path * @@ -4422,15 +4430,17 @@ static void pe_prs_frs_shared_entry(int port) PE_CLR_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_PATH); } -static void pe_prs_frs_shared_exit(int port) +__maybe_unused static void pe_prs_frs_shared_exit(int port) { + if (!IS_ENABLED(CONFIG_USB_PD_REV30)) + assert(0); + /* * Shared PRS/FRS code, when not in shared path * indicate PRS path */ PE_CLR_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_PATH); } -#endif /* CONFIG_USB_PD_REV30 */ /** * BIST TX @@ -4983,12 +4993,11 @@ static void pe_init_port_vdm_identity_request_run(int port) /* PE_INIT_PORT_VDM_Identity_ACKed embedded here */ dfp_consume_identity(port, sop, cnt, payload); -#ifdef CONFIG_CHARGE_MANAGER /* Evaluate whether this is an allow-listed charger */ - if (pd_charge_from_device(pd_get_identity_vid(port), + if (IS_ENABLED(CONFIG_CHARGE_MANAGER) && + pd_charge_from_device(pd_get_identity_vid(port), pd_get_identity_pid(port))) charge_manager_update_dualrole(port, CAP_DEDICATED); -#endif break; } case VDM_RESULT_NAK: @@ -6216,41 +6225,54 @@ void pd_dfp_discovery_init(int port) enter_usb_init(port); } -#ifdef CONFIG_USB_PD_ALT_MODE_DFP - -void pd_discovery_access_clear(int port, enum tcpm_transmit_type type) +__maybe_unused void pd_discovery_access_clear(int port, + enum tcpm_transmit_type type) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); + atomic_clear_bits(&task_access[port][type], 0xFFFFFFFF); } -bool pd_discovery_access_validate(int port, enum tcpm_transmit_type type) +__maybe_unused bool pd_discovery_access_validate(int port, + enum tcpm_transmit_type type) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); + return !(task_access[port][type] & ~BIT(task_get_current())); } -struct pd_discovery *pd_get_am_discovery(int port, enum tcpm_transmit_type type) +__maybe_unused struct pd_discovery *pd_get_am_discovery(int port, + enum tcpm_transmit_type type) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); ASSERT(type < DISCOVERY_TYPE_COUNT); atomic_or(&task_access[port][type], BIT(task_get_current())); return &pe[port].discovery[type]; } -struct partner_active_modes *pd_get_partner_active_modes(int port, - enum tcpm_transmit_type type) +__maybe_unused struct partner_active_modes *pd_get_partner_active_modes( + int port, enum tcpm_transmit_type type) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); ASSERT(type < AMODE_TYPE_COUNT); return &pe[port].partner_amodes[type]; } -void pd_set_dfp_enter_mode_flag(int port, bool set) +__maybe_unused void pd_set_dfp_enter_mode_flag(int port, bool set) { + if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) + assert(0); + if (set) PE_SET_FLAG(port, PE_FLAGS_MODAL_OPERATION); else PE_CLR_FLAG(port, PE_FLAGS_MODAL_OPERATION); } -#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ const char *pe_get_current_state(int port) { diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index c6db93376d..1f6dd28560 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -183,8 +183,7 @@ static const char * const prl_hr_state_names[] = { = "PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE", }; -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES -static const char * const rch_state_names[] = { +__maybe_unused static const char * const rch_state_names[] = { [RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER] = "RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER", [RCH_PASS_UP_MESSAGE] = "RCH_PASS_UP_MESSAGE", @@ -194,7 +193,7 @@ static const char * const rch_state_names[] = { [RCH_REPORT_ERROR] = "RCH_REPORT_ERROR", }; -static const char * const tch_state_names[] = { +__maybe_unused static const char * const tch_state_names[] = { [TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE] = "TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE", [TCH_WAIT_FOR_TRANSMISSION_COMPLETE] @@ -206,16 +205,13 @@ static const char * const tch_state_names[] = { [TCH_MESSAGE_SENT] = "TCH_MESSAGE_SENT", [TCH_REPORT_ERROR] = "TCH_REPORT_ERROR", }; -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ /* Forward declare full list of states. Index by above enums. */ static const struct usb_state prl_tx_states[]; static const struct usb_state prl_hr_states[]; -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES -static const struct usb_state rch_states[]; -static const struct usb_state tch_states[]; -#endif /* CONFIG_USB_PD_REV30 */ +__maybe_unused static const struct usb_state rch_states[]; +__maybe_unused static const struct usb_state tch_states[]; /* Chunked Rx State Machine Object */ static struct rx_chunked { @@ -396,9 +392,8 @@ static void print_current_prl_hr_state(const int port) /* Set the chunked Rx statemachine to a new state. */ static void set_state_rch(const int port, const enum usb_rch_state new_state) { -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - set_state(port, &rch[port].ctx, &rch_states[new_state]); -#endif /* CONFIG_USB_PD_REV30 */ + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + set_state(port, &rch[port].ctx, &rch_states[new_state]); } #ifdef CONFIG_USB_PD_EXTENDED_MESSAGES @@ -420,19 +415,17 @@ static void print_current_rch_state(const int port) /* Set the chunked Tx statemachine to a new state. */ static void set_state_tch(const int port, const enum usb_tch_state new_state) { -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - set_state(port, &tch[port].ctx, &tch_states[new_state]); -#endif /* CONFIG_USB_PD_REV30 */ + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + set_state(port, &tch[port].ctx, &tch_states[new_state]); } /* Get the chunked Tx statemachine's current state. */ test_export_static enum usb_tch_state tch_get_state(const int port) { -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - return tch[port].ctx.current - &tch_states[0]; -#else - return 0; -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + return tch[port].ctx.current - &tch_states[0]; + else + return 0; } #ifdef CONFIG_USB_PD_EXTENDED_MESSAGES @@ -492,10 +485,10 @@ static void prl_init(int port) prl_tx[port].last_xmit_type = TCPC_TX_SOP; prl_tx[port].xmit_status = TCPC_TX_UNSET; -#ifdef CONFIG_USB_PD_REV30 - tch[port].flags = 0; - rch[port].flags = 0; -#endif /* CONFIG_USB_PD_REV30 */ + if (IS_ENABLED(CONFIG_USB_PD_REV30)) { + tch[port].flags = 0; + rch[port].flags = 0; + } pdmsg[port].flags = 0; @@ -510,13 +503,13 @@ static void prl_init(int port) prl_tx[port].ctx = cleared; set_state_prl_tx(port, PRL_TX_PHY_LAYER_RESET); -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - rch[port].ctx = cleared; - set_state_rch(port, RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER); + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) { + rch[port].ctx = cleared; + set_state_rch(port, RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER); - tch[port].ctx = cleared; - set_state_tch(port, TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE); -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + tch[port].ctx = cleared; + set_state_tch(port, TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE); + } prl_hr[port].ctx = cleared; set_state_prl_hr(port, PRL_HR_WAIT_FOR_REQUEST); @@ -659,31 +652,32 @@ void prl_run(int port, int evt, int en) /* Run Protocol Layer Message Reception */ prl_rx_wait_for_phy_message(port, evt); -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - /* - * Run RX Chunked state machine after prl_rx. This is what - * informs the PE of incoming message. Its input is prl_rx - */ - run_state(port, &rch[port].ctx); + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) { + /* + * Run RX Chunked state machine after prl_rx. This is + * what informs the PE of incoming message. Its input + * is prl_rx + */ + run_state(port, &rch[port].ctx); - /* - * Run TX Chunked state machine before prl_tx in case we need - * to split an extended message and prl_tx can send it for us - */ - run_state(port, &tch[port].ctx); -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + /* + * Run TX Chunked state machine before prl_tx in case + * we need to split an extended message and prl_tx can + * send it for us + */ + run_state(port, &tch[port].ctx); + } /* Run Protocol Layer Message Transmission state machine */ run_state(port, &prl_tx[port].ctx); -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - /* - * Run TX Chunked state machine again after prl_tx so we can - * handle passing TX_COMPLETE (or failure) up to PE in a single - * iteration. - */ - run_state(port, &tch[port].ctx); -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) + /* + * Run TX Chunked state machine again after prl_tx so + * we can handle passing TX_COMPLETE (or failure) up + * to PE in a single iteration. + */ + run_state(port, &tch[port].ctx); /* Run Protocol Layer Hard Reset state machine */ run_state(port, &prl_hr[port].ctx); @@ -1183,10 +1177,10 @@ static void prl_hr_reset_layer_entry(const int port) */ set_state_prl_tx(port, PRL_TX_WAIT_FOR_MESSAGE_REQUEST); -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES - tch[port].flags = 0; - rch[port].flags = 0; -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) { + tch[port].flags = 0; + rch[port].flags = 0; + } pdmsg[port].flags = 0; @@ -2170,9 +2164,9 @@ static const struct usb_state prl_hr_states[] = { }, }; -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES /* All necessary Chunked Rx states (Section 6.11.2.1.2) */ -static const struct usb_state rch_states[] = { +__maybe_unused static const struct usb_state rch_states[] = { +#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES [RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER] = { .entry = rch_wait_for_message_from_protocol_layer_entry, .run = rch_wait_for_message_from_protocol_layer_run, @@ -2196,10 +2190,12 @@ static const struct usb_state rch_states[] = { .entry = rch_report_error_entry, .run = rch_report_error_run, }, +#endif }; /* All necessary Chunked Tx states (Section 6.11.2.1.3) */ -static const struct usb_state tch_states[] = { +__maybe_unused static const struct usb_state tch_states[] = { +#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES [TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE] = { .entry = tch_wait_for_message_request_from_pe_entry, .run = tch_wait_for_message_request_from_pe_run, @@ -2230,8 +2226,8 @@ static const struct usb_state tch_states[] = { [TCH_REPORT_ERROR] = { .entry = tch_report_error_entry, }, +#endif }; -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ #ifdef TEST_BUILD diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c index f6aab7dec3..ba4b9710dc 100644 --- a/common/usbc/usb_tc_ctvpd_sm.c +++ b/common/usbc/usb_tc_ctvpd_sm.c @@ -105,9 +105,9 @@ enum usb_tc_state { static const struct usb_state tc_states[]; -#ifdef CONFIG_COMMON_RUNTIME /* List of human readable state names for console debugging */ -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", [TC_ATTACH_WAIT_SNK] = "AttachWait.SNK", @@ -126,8 +126,8 @@ const char * const tc_state_names[] = { [TC_CT_DISABLED_VPD] = "CTDisabled.VPD", [TC_CT_ATTACHED_VPD] = "CTAttached.VPD", [TC_CT_ATTACH_WAIT_VPD] = "CTAttachWait.VPD", -}; #endif +}; /* Forward declare private, common functions */ static void set_state_tc(const int port, enum usb_tc_state new_state); diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 5c2c19c568..caf421fb54 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -240,9 +240,9 @@ GEN_NOT_SUPPORTED(TC_CT_ATTACHED_SNK); #define IS_ATTACHED_SNK(port) (get_state_tc(port) == TC_ATTACHED_SNK) -#ifdef USB_PD_DEBUG_LABELS /* List of human readable state names for console debugging */ -static const char * const tc_state_names[] = { +__maybe_unused static const char * const tc_state_names[] = { +#ifdef USB_PD_DEBUG_LABELS [TC_DISABLED] = "Disabled", [TC_ERROR_RECOVERY] = "ErrorRecovery", [TC_UNATTACHED_SNK] = "Unattached.SNK", @@ -269,14 +269,8 @@ static const char * const tc_state_names[] = { [TC_CC_RP] = "SS:CC_RP", [TC_STATE_COUNT] = "", -}; -#else -/* - * Reference so IS_ENABLED section below that references the names - * will compile and the optimizer will remove it. - */ -extern const char **tc_state_names; #endif +}; /* Debug log level - higher number == more log */ #ifdef CONFIG_USB_PD_DEBUG_LEVEL @@ -454,9 +448,7 @@ static __maybe_unused int reset_device_and_notify(int port); static __maybe_unused void check_drp_connection(const int port); static void sink_power_sub_states(int port); -#ifdef CONFIG_POWER_COMMON -static void handle_new_power_state(int port); -#endif /* CONFIG_POWER_COMMON */ +__maybe_unused static void handle_new_power_state(int port); static void pd_update_dual_role_config(int port); @@ -473,14 +465,15 @@ static void pd_update_try_source(void); static void sink_stop_drawing_current(int port); -#ifdef CONFIG_USB_PD_TRY_SRC -static bool is_try_src_enabled(int port) +__maybe_unused static bool is_try_src_enabled(int port) { - return IS_ENABLED(CONFIG_USB_PD_TRY_SRC) && - ((pd_try_src_override == TRY_SRC_OVERRIDE_ON) || + if (!IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + assert(0); + + return ((pd_try_src_override == TRY_SRC_OVERRIDE_ON) || (pd_try_src_override == TRY_SRC_NO_OVERRIDE && pd_try_src)); } -#endif + /* * Public Functions * @@ -649,15 +642,16 @@ static void tc_enable_pd(int port, int en) PD_DISABLED_NO_CONNECTION); } -#ifdef CONFIG_USB_PD_TRY_SRC -static void tc_enable_try_src(int en) +__maybe_unused static void tc_enable_try_src(int en) { + if (!IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + assert(0); + if (en) atomic_or(&pd_try_src, 1); else atomic_clear_bits(&pd_try_src, 1); } -#endif static void tc_detached(int port) { @@ -672,10 +666,8 @@ static inline void pd_set_dual_role_and_event(int port, { drp_state[port] = state; -#ifdef CONFIG_USB_PD_TRY_SRC if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) pd_update_try_source(); -#endif if (event != 0) task_set_event(PD_PORT_TO_TASK_ID(port), event, 0); @@ -747,7 +739,7 @@ static inline void pd_dev_dump_info(uint16_t dev_id, uint32_t *hash) ccprintf("DevId:%d.%d Hash:", HW_DEV_ID_MAJ(dev_id), HW_DEV_ID_MIN(dev_id)); for (j = 0; j < PD_RW_HASH_SIZE / 4; j++) - ccprintf(" %08x ", hash[i]); + ccprintf(" %08x ", hash[j]); ccprintf("\n"); } #endif /* CONFIG_CMD_PD_DEV_DUMP_INFO */ @@ -846,14 +838,13 @@ void pd_try_vconn_src(int port) int tc_check_vconn_swap(int port) { -#ifdef CONFIG_USBC_VCONN - if (TC_CHK_FLAG(port, TC_FLAGS_REJECT_VCONN_SWAP)) - return 0; + if (IS_ENABLED(CONFIG_USBC_VCONN)) { + if (TC_CHK_FLAG(port, TC_FLAGS_REJECT_VCONN_SWAP)) + return 0; - return pd_check_vconn_swap(port); -#else - return 0; -#endif + return pd_check_vconn_swap(port); + } else + return 0; } void tc_pr_swap_complete(int port, bool success) @@ -944,9 +935,11 @@ void tc_disc_ident_complete(int port) TC_CLR_FLAG(port, TC_FLAGS_DISC_IDENT_IN_PROGRESS); } -#ifdef CONFIG_USB_PD_TRY_SRC void tc_try_src_override(enum try_src_override_t ov) { + if (!IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + assert(0); + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) { switch (ov) { case TRY_SRC_OVERRIDE_OFF: /* 0 */ @@ -963,9 +956,11 @@ void tc_try_src_override(enum try_src_override_t ov) enum try_src_override_t tc_get_try_src_override(void) { + if (!IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + assert(0); + return pd_try_src_override; } -#endif void tc_snk_power_off(int port) { @@ -1103,9 +1098,8 @@ void pd_vbus_low(int port) int pd_is_connected(int port) { return (IS_ATTACHED_SRC(port) || -#ifdef CONFIG_USB_PE_SM - (get_state_tc(port) == TC_CT_ATTACHED_SNK) || -#endif + (IS_ENABLED(CONFIG_USB_PE_SM) && + (get_state_tc(port) == TC_CT_ATTACHED_SNK)) || IS_ATTACHED_SNK(port)); } @@ -1243,10 +1237,10 @@ static bool tc_perform_snk_hard_reset(int port) * the Port with the Rd resistor asserted to turn off * VCONN. */ -#ifdef CONFIG_USBC_VCONN - if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON)) + if (IS_ENABLED(CONFIG_USBC_VCONN) && + TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON)) set_vconn(port, 0); -#endif + /* Wait tSafe0V + tSrcRecover, then check for Vbus presence */ tc[port].ps_reset_state = PS_STATE1; tc[port].timeout = get_time().val + PD_T_SAFE_0V + @@ -1386,10 +1380,9 @@ void tc_state_init(int port) } -#ifdef CONFIG_USB_PD_TRY_SRC /* Allow system to set try src enable */ - tc_try_src_override(TRY_SRC_NO_OVERRIDE); -#endif + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + tc_try_src_override(TRY_SRC_NO_OVERRIDE); /* * Set initial PD communication policy. @@ -1537,23 +1530,19 @@ void tc_event_check(int port, int evt) } #endif /* CONFIG_POWER_COMMON */ -#ifdef CONFIG_USB_PD_ALT_MODE_DFP - { + if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { int i; - if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { - /* - * Notify all ports of sysjump - */ - if (evt & PD_EVENT_SYSJUMP) { - for (i = 0; i < - CONFIG_USB_PD_PORT_MAX_COUNT; i++) - dpm_set_mode_exit_request(i); - notify_sysjump_ready(); - } + /* + * Notify all ports of sysjump + */ + if (evt & PD_EVENT_SYSJUMP) { + for (i = 0; i < + CONFIG_USB_PD_PORT_MAX_COUNT; i++) + dpm_set_mode_exit_request(i); + notify_sysjump_ready(); } } -#endif if (evt & PD_EVENT_UPDATE_DUAL_ROLE) pd_update_dual_role_config(port); @@ -1668,9 +1657,11 @@ static void pd_update_dual_role_config(int port) } } -#ifdef CONFIG_POWER_COMMON -static void handle_new_power_state(int port) +__maybe_unused static void handle_new_power_state(int port) { + if (!IS_ENABLED(CONFIG_POWER_COMMON)) + assert(0); + if (IS_ENABLED(CONFIG_POWER_COMMON) && IS_ENABLED(CONFIG_USB_PE_SM)) { if (chipset_in_or_transitioning_to_state( @@ -1689,7 +1680,6 @@ static void handle_new_power_state(int port) } } } -#endif /* CONFIG_POWER_COMMON */ #if defined(CONFIG_USB_PD_ALT_MODE) && !defined(CONFIG_USB_PD_ALT_MODE_DFP) void pd_send_hpd(int port, enum hpd_event hpd) @@ -1839,9 +1829,6 @@ void pd_prevent_low_power_mode(int port, int prevent) { const int current_task_mask = (1 << task_get_current()); - if (!IS_ENABLED(CONFIG_USB_PD_TCPC_LOW_POWER)) - return; - if (prevent) atomic_or(&tc[port].tasks_preventing_lpm, current_task_mask); else @@ -1967,12 +1954,12 @@ static void tc_error_recovery_run(const int port) * If try src support is active (e.g. in S0). Then try to become the * SRC, otherwise we should try to be the sink. */ -#ifdef CONFIG_USB_PD_TRY_SRC - restart_tc_sm(port, is_try_src_enabled(port) ? TC_UNATTACHED_SRC : - TC_UNATTACHED_SNK); -#else - restart_tc_sm(port, TC_UNATTACHED_SNK); -#endif + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + restart_tc_sm(port, is_try_src_enabled(port) + ? TC_UNATTACHED_SRC + : TC_UNATTACHED_SNK); + else + restart_tc_sm(port, TC_UNATTACHED_SNK); } /** @@ -2175,11 +2162,10 @@ static void tc_attach_wait_snk_run(const int port) */ if (pd_is_vbus_present(port)) { if (new_cc_state == PD_CC_DFP_ATTACHED) { -#ifdef CONFIG_USB_PD_TRY_SRC - if (is_try_src_enabled(port)) + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC) && + is_try_src_enabled(port)) set_state_tc(port, TC_TRY_SRC); else -#endif set_state_tc(port, TC_ATTACHED_SNK); } else { /* new_cc_state is PD_CC_DFP_DEBUG_ACC */ @@ -2219,8 +2205,8 @@ static void tc_attached_snk_entry(const int port) if (IS_ENABLED(CONFIG_USBC_PPC)) ppc_dev_is_connected(port, PPC_DEV_SRC); -#ifdef CONFIG_USB_PE_SM - if (TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) { + if (IS_ENABLED(CONFIG_USB_PE_SM) && + TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) { /* Flipping power role - Disable AutoDischargeDisconnect */ tcpm_enable_auto_discharge_disconnect(port, 0); @@ -2238,9 +2224,7 @@ static void tc_attached_snk_entry(const int port) * AutoDischargeDisconnect until the swap is completed * and tc_pr_swap_complete is called. */ - } else -#endif - { + } else { /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); tc[port].polarity = get_snk_polarity(cc1, cc2); @@ -2386,12 +2370,12 @@ static void tc_attached_snk_run(const int port) PD_ROLE_DFP : PD_ROLE_UFP); } -#ifdef CONFIG_USBC_VCONN /* * VCONN Swap * UnorientedDebugAccessory.SRC shall not drive Vconn */ - if (!TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) { + if (IS_ENABLED(CONFIG_USBC_VCONN) && + !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) { if (TC_CHK_FLAG(port, TC_FLAGS_REQUEST_VC_SWAP_ON)) { TC_CLR_FLAG(port, TC_FLAGS_REQUEST_VC_SWAP_ON); @@ -2413,7 +2397,7 @@ static void tc_attached_snk_run(const int port) pe_vconn_swap_complete(port); } } -#endif + if (!TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) { /* * If the port supports Charge-Through VCONN-Powered USB @@ -2683,25 +2667,72 @@ static void tc_attached_src_entry(const int port) typec_select_pull(port, TYPEC_CC_RP); typec_select_src_current_limit_rp(port, CONFIG_USB_PD_PULLUP); -#if defined(CONFIG_USB_PE_SM) - if (TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) { - /* Change role to source */ - tc_set_power_role(port, PD_ROLE_SOURCE); - tcpm_set_msg_header(port, - tc[port].power_role, tc[port].data_role); + if (IS_ENABLED(CONFIG_USB_PE_SM)) { + if (TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) { + /* Change role to source */ + tc_set_power_role(port, PD_ROLE_SOURCE); + tcpm_set_msg_header(port, + tc[port].power_role, + tc[port].data_role); - /* Enable VBUS */ - tc_src_power_on(port); + /* Enable VBUS */ + tc_src_power_on(port); - /* Apply Rp */ - typec_update_cc(port); + /* Apply Rp */ + typec_update_cc(port); - /* - * Maintain VCONN supply state, whether ON or OFF, and its - * data role / usb mux connections. Do not re-enable - * AutoDischargeDisconnect until the swap is completed - * and tc_pr_swap_complete is called. - */ + /* + * Maintain VCONN supply state, whether ON or OFF, and + * its data role / usb mux connections. Do not + * re-enable AutoDischargeDisconnect until the swap is + * completed and tc_pr_swap_complete is called. + */ + } else { + /* Get connector orientation */ + tcpm_get_cc(port, &cc1, &cc2); + tc[port].polarity = get_src_polarity(cc1, cc2); + pd_set_polarity(port, tc[port].polarity); + + /* + * Initial data role for sink is DFP + * This also sets the usb mux + */ + tc_set_data_role(port, PD_ROLE_DFP); + + /* + * Start sourcing Vconn before Vbus to ensure + * we are within USB Type-C Spec 1.4 tVconnON + * + * UnorientedDebugAccessory.SRC shall not drive Vconn + */ + if (IS_ENABLED(CONFIG_USBC_VCONN) && + !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) + set_vconn(port, 1); + + /* Enable VBUS */ + if (tc_src_power_on(port)) { + /* Stop sourcing Vconn if Vbus failed */ + if (IS_ENABLED(CONFIG_USBC_VCONN)) + set_vconn(port, 0); + + if (IS_ENABLED(CONFIG_USBC_SS_MUX)) + usb_mux_set(port, + USB_PD_MUX_NONE, + USB_SWITCH_DISCONNECT, + tc[port].polarity); + } + + /* Attached.SRC - enable AutoDischargeDisconnect */ + tcpm_enable_auto_discharge_disconnect(port, 1); + + /* Apply Rp */ + typec_update_cc(port); + + tc_enable_pd(port, 0); + tc[port].timeout = get_time().val + + MAX(PD_POWER_SUPPLY_TURN_ON_DELAY, + PD_T_VCONN_STABLE); + } } else { /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); @@ -2721,7 +2752,7 @@ static void tc_attached_src_entry(const int port) * UnorientedDebugAccessory.SRC shall not drive Vconn */ if (IS_ENABLED(CONFIG_USBC_VCONN) && - !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) + !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) set_vconn(port, 1); /* Enable VBUS */ @@ -2740,52 +2771,8 @@ static void tc_attached_src_entry(const int port) /* Apply Rp */ typec_update_cc(port); - - tc_enable_pd(port, 0); - tc[port].timeout = get_time().val + - MAX(PD_POWER_SUPPLY_TURN_ON_DELAY, PD_T_VCONN_STABLE); - } -#else - /* Get connector orientation */ - tcpm_get_cc(port, &cc1, &cc2); - tc[port].polarity = get_src_polarity(cc1, cc2); - pd_set_polarity(port, tc[port].polarity); - - /* - * Initial data role for sink is DFP - * This also sets the usb mux - */ - tc_set_data_role(port, PD_ROLE_DFP); - - /* - * Start sourcing Vconn before Vbus to ensure - * we are within USB Type-C Spec 1.4 tVconnON - * - * UnorientedDebugAccessory.SRC shall not drive Vconn - */ - if (IS_ENABLED(CONFIG_USBC_VCONN) && - !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) - set_vconn(port, 1); - - /* Enable VBUS */ - if (tc_src_power_on(port)) { - /* Stop sourcing Vconn if Vbus failed */ - if (IS_ENABLED(CONFIG_USBC_VCONN)) - set_vconn(port, 0); - - if (IS_ENABLED(CONFIG_USBC_SS_MUX)) - usb_mux_set(port, USB_PD_MUX_NONE, - USB_SWITCH_DISCONNECT, tc[port].polarity); } - /* Attached.SRC - enable AutoDischargeDisconnect */ - tcpm_enable_auto_discharge_disconnect(port, 1); - - /* Apply Rp */ - typec_update_cc(port); - -#endif /* CONFIG_USB_PE_SM */ - /* Inform PPC that a sink is connected. */ if (IS_ENABLED(CONFIG_USBC_PPC)) ppc_dev_is_connected(port, PPC_DEV_SNK); @@ -2830,25 +2817,24 @@ static void tc_attached_src_run(const int port) if (tc[port].cc_state == PD_CC_NONE && !TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS) && !TC_CHK_FLAG(port, TC_FLAGS_DISC_IDENT_IN_PROGRESS)) { + bool tryWait; -#ifdef CONFIG_USB_PD_TRY_SRC - const bool tryWait = is_try_src_enabled(port) && + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + tryWait = is_try_src_enabled(port) && !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER); -#endif - if (IS_ENABLED(CONFIG_USB_PE_SM)) - if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { - pd_dfp_exit_mode(port, TCPC_TX_SOP, 0, 0); - pd_dfp_exit_mode(port, TCPC_TX_SOP_PRIME, 0, 0); - pd_dfp_exit_mode(port, TCPC_TX_SOP_PRIME_PRIME, - 0, 0); - } -#ifdef CONFIG_USB_PD_TRY_SRC - set_state_tc(port, tryWait ? + if (IS_ENABLED(CONFIG_USB_PE_SM) && + IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { + pd_dfp_exit_mode(port, TCPC_TX_SOP, 0, 0); + pd_dfp_exit_mode(port, TCPC_TX_SOP_PRIME, 0, 0); + pd_dfp_exit_mode(port, TCPC_TX_SOP_PRIME_PRIME, 0, 0); + } + + if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC)) + set_state_tc(port, tryWait ? TC_TRY_WAIT_SNK : TC_UNATTACHED_SNK); -#else - set_state_tc(port, TC_UNATTACHED_SNK); -#endif + else + set_state_tc(port, TC_UNATTACHED_SNK); return; } @@ -3027,12 +3013,14 @@ static __maybe_unused void check_drp_connection(const int port) } } -#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE /** * DrpAutoToggle */ -static void tc_drp_auto_toggle_entry(const int port) +__maybe_unused static void tc_drp_auto_toggle_entry(const int port) { + if (!IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE)) + assert(0); + print_current_state(port); /* @@ -3043,8 +3031,11 @@ static void tc_drp_auto_toggle_entry(const int port) tc[port].timeout = get_time().val + MAX(PD_T_DRP_SNK, PD_T_DRP_SRC); } -static void tc_drp_auto_toggle_run(const int port) +__maybe_unused static void tc_drp_auto_toggle_run(const int port) { + if (!IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE)) + assert(0); + /* * A timer is running, but if a connection comes in while waiting * then allow that to take higher priority. @@ -3064,18 +3055,22 @@ static void tc_drp_auto_toggle_run(const int port) } } } -#endif /* CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE */ -#ifdef CONFIG_USB_PD_TCPC_LOW_POWER -static void tc_low_power_mode_entry(const int port) +__maybe_unused static void tc_low_power_mode_entry(const int port) { + if (!IS_ENABLED(CONFIG_USB_PD_TCPC_LOW_POWER)) + assert(0); + print_current_state(port); tc[port].low_power_time = get_time().val + PD_LPM_DEBOUNCE_US; tc[port].low_power_exit_time = 0; } -static void tc_low_power_mode_run(const int port) +__maybe_unused static void tc_low_power_mode_run(const int port) { + if (!IS_ENABLED(CONFIG_USB_PD_TCPC_LOW_POWER)) + assert(0); + if (TC_CHK_FLAG(port, TC_FLAGS_CHECK_CONNECTION)) { uint64_t now = get_time().val; @@ -3104,7 +3099,6 @@ static void tc_low_power_mode_run(const int port) tc[port].low_power_exit_time = 0; } } -#endif /* CONFIG_USB_PD_TCPC_LOW_POWER */ /** @@ -3249,15 +3243,16 @@ static void tc_try_wait_snk_run(const int port) pd_is_vbus_present(port)) set_state_tc(port, TC_ATTACHED_SNK); } - #endif -#if defined(CONFIG_USB_PE_SM) /* * CTUnattached.SNK */ -static void tc_ct_unattached_snk_entry(int port) +__maybe_unused static void tc_ct_unattached_snk_entry(int port) { + if (!IS_ENABLED(CONFIG_USB_PE_SM)) + assert(0); + print_current_state(port); /* @@ -3283,12 +3278,15 @@ static void tc_ct_unattached_snk_entry(int port) tc[port].timeout = get_time().val + PD_POWER_SUPPLY_TURN_ON_DELAY; } -static void tc_ct_unattached_snk_run(int port) +__maybe_unused static void tc_ct_unattached_snk_run(int port) { enum tcpc_cc_voltage_status cc1; enum tcpc_cc_voltage_status cc2; enum pd_cc_states new_cc_state; + if (!IS_ENABLED(CONFIG_USB_PE_SM)) + assert(0); + if (tc[port].timeout > 0 && get_time().val > tc[port].timeout) { tc_enable_pd(port, 1); tc[port].timeout = 0; @@ -3355,16 +3353,22 @@ static void tc_ct_unattached_snk_run(int port) /** * CTAttached.SNK */ -static void tc_ct_attached_snk_entry(int port) +__maybe_unused static void tc_ct_attached_snk_entry(int port) { + if (!IS_ENABLED(CONFIG_USB_PE_SM)) + assert(0); + print_current_state(port); /* The port shall reject a VCONN swap request. */ TC_SET_FLAG(port, TC_FLAGS_REJECT_VCONN_SWAP); } -static void tc_ct_attached_snk_run(int port) +__maybe_unused static void tc_ct_attached_snk_run(int port) { + if (!IS_ENABLED(CONFIG_USB_PE_SM)) + assert(0); + /* * Hard Reset is sent when the PE layer is disabled due to a * CTVPD connection. @@ -3394,14 +3398,16 @@ static void tc_ct_attached_snk_run(int port) sink_power_sub_states(port); } -static void tc_ct_attached_snk_exit(int port) +__maybe_unused static void tc_ct_attached_snk_exit(int port) { + if (!IS_ENABLED(CONFIG_USB_PE_SM)) + assert(0); + /* Stop drawing power */ sink_stop_drawing_current(port); TC_CLR_FLAG(port, TC_FLAGS_REJECT_VCONN_SWAP); } -#endif /* CONFIG_USB_PE_SM */ /** * Super State CC_RD @@ -3491,10 +3497,9 @@ void tc_run(const int port) * DISABLED */ if (TC_CHK_FLAG(port, TC_FLAGS_SUSPEND)) { -#ifdef CONFIG_USB_PE_SM /* Invalidate a contract, if there is one */ - pe_invalidate_explicit_contract(port); -#endif + if (IS_ENABLED(CONFIG_USB_PE_SM)) + pe_invalidate_explicit_contract(port); set_state_tc(port, TC_DISABLED); } diff --git a/common/usbc/usb_tc_vpd_sm.c b/common/usbc/usb_tc_vpd_sm.c index 7d25001813..171c219705 100644 --- a/common/usbc/usb_tc_vpd_sm.c +++ b/common/usbc/usb_tc_vpd_sm.c @@ -59,15 +59,15 @@ 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[]; -#ifdef CONFIG_COMMON_RUNTIME /* List of human readable state names for console debugging */ -static const char * const tc_state_names[] = { +__maybe_unused static const char * const tc_state_names[] = { +#ifdef CONFIG_COMMON_RUNTIME [TC_DISABLED] = "Disabled", [TC_UNATTACHED_SNK] = "Unattached.SNK", [TC_ATTACH_WAIT_SNK] = "AttachWait.SNK", [TC_ATTACHED_SNK] = "Attached.SNK", -}; #endif +}; /* Forward declare private, common functions */ static void set_state_tc(const int port, enum usb_tc_state new_state); |