summaryrefslogtreecommitdiff
path: root/common/usb_pd_alt_mode_dfp.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/usb_pd_alt_mode_dfp.c')
-rw-r--r--common/usb_pd_alt_mode_dfp.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c
index 051fa9740c..42b21a6fa8 100644
--- a/common/usb_pd_alt_mode_dfp.c
+++ b/common/usb_pd_alt_mode_dfp.c
@@ -881,27 +881,47 @@ __overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
* ############################################################################
*/
-enum usb_rev30_ss get_usb4_cable_speed(int port)
+/*
+ * For Cable rev 3.0: USB4 cable speed is set according to speed supported by
+ * the port and the response received from the cable, whichever is least.
+ *
+ * For Cable rev 2.0: Since board_is_tbt_usb4_port() should not enabled if the
+ * port supports speed less than USB_R20_SS_U31_GEN1_GEN2, USB4 cable speed is
+ * set according to the cable response.
+ */
+static enum usb_rev30_ss board_get_max_usb_cable_speed(int port)
{
struct pd_cable *cable = pd_get_cable_attributes(port);
-
/*
- * TODO: Return USB4 cable speed for USB3.2 Gen 2 cables if DFP isn't
- * Gen 3 capable.
+ * Converting Thunderbolt-Compatible board speed to equivalent USB4
+ * speed.
*/
- if ((cable->rev == PD_REV30) &&
- (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) &&
- ((cable->attr.p_rev30.ss != USB_R30_SS_U32_U40_GEN2) ||
- !IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE))) {
- return cable->attr.p_rev30.ss;
- }
+ enum usb_rev30_ss max_usb4_speed =
+ board_get_max_tbt_speed(port) == TBT_SS_TBT_GEN3 ?
+ USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2;
+ return max_usb4_speed < cable->attr.p_rev30.ss ?
+ max_usb4_speed : cable->attr.p_rev30.ss;
+}
+
+enum usb_rev30_ss get_usb4_cable_speed(int port)
+{
+ struct pd_cable *cable = pd_get_cable_attributes(port);
+ enum usb_rev30_ss max_rev30_usb4_speed;
+
+ if (cable->rev == PD_REV30) {
+ max_rev30_usb4_speed = board_get_max_usb_cable_speed(port);
+ if (!IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE) ||
+ max_rev30_usb4_speed != USB_R30_SS_U32_U40_GEN2 ||
+ get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE)
+ return max_rev30_usb4_speed;
+ }
/*
* Converting Thunderolt-Compatible cable speed to equivalent USB4 cable
* speed.
*/
- return cable->cable_mode_resp.tbt_cable_speed == TBT_SS_TBT_GEN3 ?
- USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2;
+ return get_tbt_cable_speed(port) == TBT_SS_TBT_GEN3 ?
+ USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2;
}
__overridable void svdm_safe_dp_mode(int port)