@@ -432,6 +432,25 @@ static int pmc_usb_connect(struct pmc_usb_port *port, enum usb_role role)
return pmc_usb_command(port, msg, sizeof(msg));
}
+static bool
+pmc_usb_mux_allow_to_enter_safe_mode(struct pmc_usb_port *port,
+ struct typec_mux_state *state)
+{
+ if ((IOM_PORT_ACTIVITY_IS(port->iom_status, DP) ||
+ IOM_PORT_ACTIVITY_IS(port->iom_status, DP_MFD)) &&
+ state->alt &&
+ state->alt->svid == USB_TYPEC_DP_SID)
+ return false;
+
+ if ((IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) ||
+ IOM_PORT_ACTIVITY_IS(port->iom_status, ALT_MODE_TBT_USB)) &&
+ state->alt &&
+ state->alt->svid == USB_TYPEC_TBT_SID)
+ return false;
+
+ return true;
+}
+
static int
pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
{
@@ -442,8 +461,13 @@ pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
if (port->orientation == TYPEC_ORIENTATION_NONE || port->role == USB_ROLE_NONE)
return 0;
- if (state->mode == TYPEC_STATE_SAFE)
+ if (state->mode == TYPEC_STATE_SAFE) {
+ if (!pmc_usb_mux_allow_to_enter_safe_mode(port, state))
+ return 0;
+
return pmc_usb_mux_safe_state(port);
+ }
+
if (state->mode == TYPEC_STATE_USB)
return pmc_usb_connect(port, port->role);