[PATCH v5 3/3] platform/chrome: cros_ec_typec: Re-order connector configuration steps

From: Azhar Shaikh
Date: Fri Aug 21 2020 - 17:46:45 EST


As per USB Type-C Spec R2.0 section 4.5.1.2 (Connecting Sources and Sinks)
and section 4.5.2.2 (Connection State Machine Requirements), the typical
flow for configuring a device connected to a typeC port is as below:

1. Source/sink detection
2. Orientation
3. Data role
4. VCONN
5. VBUS (USB Type-C currents)
6. The connector is now configured. We can start the PD communication
that should lead into configuration of the mux if we enter a mode.

But in existing code data role was set after the connector and mux are
already configured. So fix this by following the spec to set the data
role before the connector and mux are configured.

Signed-off-by: Azhar Shaikh <azhar.shaikh@xxxxxxxxx>
Reviewed-by: Prashant Malani <pmalani@xxxxxxxxxxxx>
Reviewed-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
---
Changes in v5:
- Rebased on top of https://lkml.org/lkml/2020/7/10/1063
- Added Reviewed-by from v4

Changes in v4:
- No change

Changes in v3:
- New patch added

drivers/platform/chrome/cros_ec_typec.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 39989069decf..31be31161350 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -545,6 +545,12 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
if (ret)
return ret;

+ ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw,
+ pd_ctrl->role & PD_CTRL_RESP_ROLE_DATA
+ ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+ if (ret)
+ return ret;
+
if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
} else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
@@ -564,12 +570,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
ret = -ENOTSUPP;
}

- if (ret)
- return ret;
-
- return usb_role_switch_set_role(typec->ports[port_num]->role_sw,
- pd_ctrl->role & PD_CTRL_RESP_ROLE_DATA
- ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+ return ret;
}

static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
--
2.17.1