summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2021-02-11 16:23:09 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-16 23:52:44 +0000
commit6a077f21f25be5b0ec7073af2adbba1dd9e261b7 (patch)
tree605d4dfec1311e7963dec7f63a93adcddcf5d980
parentb3a07b9b2eb966d13e315db76cd3775ca42d4a0c (diff)
downloadchrome-ec-6a077f21f25be5b0ec7073af2adbba1dd9e261b7.tar.gz
TCPMv2: Refactor PD 3.0 check into FRS enable
To reduce code indenting, add the check for CONFIG_USB_PD_REV30 into the pe_set_frs_enable function. Also move typec current limit setting into the FRS enable function. BRANCH=None BUG=None TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Id272c40c447c799f299fb59294c77a1603ccc1c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2692028 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--common/usbc/usb_pe_drp_sm.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 9fb5ba81af..e2cf4cf696 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -473,7 +473,6 @@ GEN_NOT_SUPPORTED(PE_SRC_CHUNK_RECEIVED);
#define PE_SRC_CHUNK_RECEIVED PE_SRC_CHUNK_RECEIVED_NOT_SUPPORTED
GEN_NOT_SUPPORTED(PE_SNK_CHUNK_RECEIVED);
#define PE_SNK_CHUNK_RECEIVED PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED
-void pe_set_frs_enable(int port, int enable);
#endif /* CONFIG_USB_PD_REV30 */
#ifndef CONFIG_USB_PD_EXTENDED_MESSAGES
@@ -1019,6 +1018,7 @@ void pd_got_frs_signal(int port)
PE_SET_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_SIGNALED);
task_wake(PD_PORT_TO_TASK_ID(port));
}
+#endif /* CONFIG_USB_PD_REV30 */
/*
* PE_Set_FRS_Enable
@@ -1033,26 +1033,32 @@ void pd_got_frs_signal(int port)
*/
static void pe_set_frs_enable(int port, int enable)
{
+ int current = PE_CHK_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
+
/* This should only be called from the PD task */
assert(port == TASK_ID_TO_PD_PORT(task_get_current()));
- if (IS_ENABLED(CONFIG_USB_PD_FRS)) {
- int current = PE_CHK_FLAG(port,
- PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
+ if (!IS_ENABLED(CONFIG_USB_PD_FRS) || !IS_ENABLED(CONFIG_USB_PD_REV30))
+ return;
- /* Request an FRS change, only if the state has changed */
- if (!!current != !!enable) {
- pd_set_frs_enable(port, enable);
- if (enable)
- PE_SET_FLAG(port,
- PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
- else
- PE_CLR_FLAG(port,
- PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
- }
+ /* Request an FRS change, only if the state has changed */
+ if (!!current == !!enable)
+ return;
+
+ pd_set_frs_enable(port, enable);
+ if (enable) {
+ int curr_limit = *pd_get_snk_caps(port)
+ & PDO_FIXED_FRS_CURR_MASK;
+
+ typec_set_source_current_limit(port,
+ curr_limit ==
+ PDO_FIXED_FRS_CURR_3A0_AT_5V ?
+ TYPEC_RP_3A0 : TYPEC_RP_1A5);
+ PE_SET_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
+ } else {
+ PE_CLR_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
}
}
-#endif /* CONFIG_USB_PD_REV30 */
void pe_set_explicit_contract(int port)
{
@@ -1065,8 +1071,7 @@ void pe_set_explicit_contract(int port)
void pe_invalidate_explicit_contract(int port)
{
- if (IS_ENABLED(CONFIG_USB_PD_REV30))
- pe_set_frs_enable(port, 0);
+ pe_set_frs_enable(port, 0);
PE_CLR_FLAG(port, PE_FLAGS_EXPLICIT_CONTRACT);
@@ -1720,25 +1725,13 @@ static bool sink_dpm_requests(int port)
return true;
} else if (PE_CHK_DPM_REQUEST(port,
DPM_REQUEST_FRS_DET_ENABLE)) {
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- IS_ENABLED(CONFIG_USB_PD_FRS)) {
- int curr_limit = *pd_get_snk_caps(port)
- & PDO_FIXED_FRS_CURR_MASK;
-
- typec_set_source_current_limit(port,
- curr_limit ==
- PDO_FIXED_FRS_CURR_3A0_AT_5V ?
- TYPEC_RP_3A0 : TYPEC_RP_1A5);
- pe_set_frs_enable(port, 1);
- }
+ pe_set_frs_enable(port, 1);
/* Requires no state change, fall through to false */
PE_CLR_DPM_REQUEST(port, DPM_REQUEST_FRS_DET_ENABLE);
} else if (PE_CHK_DPM_REQUEST(port,
DPM_REQUEST_FRS_DET_DISABLE)) {
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- IS_ENABLED(CONFIG_USB_PD_FRS))
- pe_set_frs_enable(port, 0);
+ pe_set_frs_enable(port, 0);
/* Requires no state change, fall through to false */
PE_CLR_DPM_REQUEST(port, DPM_REQUEST_FRS_DET_DISABLE);