diff options
-rw-r--r-- | common/usb_common.c | 6 | ||||
-rw-r--r-- | common/usbc/usb_tc_drp_acc_trysrc_sm.c | 5 | ||||
-rw-r--r-- | driver/tcpm/tcpci.c | 3 | ||||
-rw-r--r-- | driver/tcpm/tcpci.h | 4 | ||||
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | include/usb_pd.h | 9 | ||||
-rw-r--r-- | test/fake_usbc.c | 5 | ||||
-rw-r--r-- | test/test_config.h | 2 |
8 files changed, 32 insertions, 3 deletions
diff --git a/common/usb_common.c b/common/usb_common.c index 3011189ca7..ec28e72bf9 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -303,6 +303,12 @@ __overridable uint8_t board_get_usb_pd_port_count(void) return CONFIG_USB_PD_PORT_MAX_COUNT; } +int pd_get_retry_count(int port, enum tcpm_transmit_type type) +{ + /* PD 3.0 6.7.7: nRetryCount = 2; PD 2.0 6.6.9: nRetryCount = 3 */ + return pd_get_rev(port, type) == PD_REV30 ? 2 : 3; +} + enum pd_drp_next_states drp_auto_toggle_next_state( uint64_t *drp_sink_time, enum pd_power_role power_role, diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 519dbab8f6..74b3552309 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -521,6 +521,11 @@ void pd_set_src_caps(int port, int cnt, uint32_t *src_caps) { } +int pd_get_rev(int port, enum tcpm_transmit_type type) +{ + return PD_REV30; +} + #endif /* !CONFIG_USB_PR_SM */ void pd_update_contract(int port) diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index c667f4b896..be1a0766dc 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -1004,7 +1004,8 @@ int tcpci_tcpm_transmit(int port, enum tcpm_transmit_type type, * supported at build time. */ return tcpc_write(port, TCPC_REG_TRANSMIT, - TCPC_REG_TRANSMIT_SET_WITH_RETRY(type)); + TCPC_REG_TRANSMIT_SET_WITH_RETRY( + pd_get_retry_count(port, type), type)); } /* diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index 594e3adc3c..309c7c654b 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -183,8 +183,8 @@ #define TCPC_REG_RX_BUFFER 0x30 #define TCPC_REG_TRANSMIT 0x50 -#define TCPC_REG_TRANSMIT_SET_WITH_RETRY(type) \ - (CONFIG_PD_RETRY_COUNT << 4 | (type)) +#define TCPC_REG_TRANSMIT_SET_WITH_RETRY(retries, type) \ + ((retries) << 4 | (type)) #define TCPC_REG_TRANSMIT_SET_WITHOUT_RETRY(type) (type) #define TCPC_REG_TRANSMIT_RETRY(reg) (((reg) & 0x30) >> 4) #define TCPC_REG_TRANSMIT_TYPE(reg) ((reg) & 0x7) diff --git a/include/config.h b/include/config.h index 03c5c6623b..8ff2eeea50 100644 --- a/include/config.h +++ b/include/config.h @@ -5035,6 +5035,7 @@ * PD 2.0 retires three times (for a total of 4 attempts). * * Note must be [0-3] since it must fit within 2 bits. + * TODO(b/175236718): Set retry count dynamically based on active spec revision. */ #ifdef CONFIG_USB_PD_REV30 #define CONFIG_PD_RETRY_COUNT 2 diff --git a/include/usb_pd.h b/include/usb_pd.h index 64e2828363..f6f097196a 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1342,6 +1342,15 @@ int pd_get_rev(int port, enum tcpm_transmit_type type); int pd_get_vdo_ver(int port, enum tcpm_transmit_type type); /** + * Get transmit retry count for active PD revision. + * + * @param port The port to query + * @param type The partner to query (SOP, SOP', or SOP'') + * @return The number of retries to perform when transmitting. + */ +int pd_get_retry_count(int port, enum tcpm_transmit_type type); + +/** * Check if max voltage request is allowed (only used if * CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED is defined). * diff --git a/test/fake_usbc.c b/test/fake_usbc.c index dc513b5be9..3f84f26219 100644 --- a/test/fake_usbc.c +++ b/test/fake_usbc.c @@ -56,6 +56,11 @@ __overridable enum pd_cable_plug tc_get_cable_plug(int port) return PD_PLUG_FROM_DFP_UFP; } +__overridable int pd_get_rev(int port, enum tcpm_transmit_type type) +{ + return IS_ENABLED(CONFIG_USB_PD_REV30) ? PD_REV30 : PD_REV20; +} + int tc_check_vconn_swap(int port) { return 0; diff --git a/test/test_config.h b/test/test_config.h index 4e9024f6c1..00dbcab5c9 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -477,6 +477,8 @@ int ncp15wb_calculate_temp(uint16_t adc); #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE #define CONFIG_USB_PD_REV30 +#undef CONFIG_PD_RETRY_COUNT +#define CONFIG_PD_RETRY_COUNT 2 #define CONFIG_USB_PD_TCPC_LOW_POWER #define CONFIG_USB_PD_TRY_SRC #define CONFIG_USB_PD_TCPMV2 |